-
Notifications
You must be signed in to change notification settings - Fork 51
Mixins : Decomposable
johnmcclean-aol edited this page Feb 24, 2016
·
2 revisions
Cyclops has merged with simple-react. Please update your bookmarks (stars :) ) to https://github.com/aol/cyclops-react
All new develpoment on cyclops occurs in cyclops-react. Older modules are still available in maven central.
Implementing com.aol.cyclops.lambda.api.Decomposable adds a default unapply method that decomposes the host Object into an Iterable over it's fields. This can be very useful for pattern matching recursively against fields.
Any Object can be coerced to a Decomposable via the following methods
- AsDecomposable.asDecomposable
- As.asDecomposable
- If the Object is an iterable it will be returned
- Otherwise, the values of the Object fields will be returned in an Immutable Array List
With Lombok @Value
assertThat(As.asDecomposable(new MyCase("key",10))
.unapply(),equalTo(Arrays.asList("key",10)));
@Value static class MyCase { String key; int value;}