-
Notifications
You must be signed in to change notification settings - Fork 51
Wrappers : Monad
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.
As of v5.0.0 Monad has been made an internal interface. Use AnyM to wrap Monad types instead.
com.aol.cyclops.lambda.monads.Monad is a generic interface that can wrap around a Monad implementation (such as java.util.Stream)
Monads can be coerced to the generic Monad interface via
- AsMonad.asMonad
- As.asMonad
com.aol.cyclops.lambda.api.Monad provides
Monad methods / functions
- flatMap
- bind (looser typed version of flatMap that allows a different Monad type to be returned)
The Monad interface doesn't provide Unit as it wraps prexisting Monad Objects.
- map
- filter
- peek
- liftAndBind
- allMatch
- anyMatch
- findFirst
- findAny
- toList
- toSet
- reduce (monoid)
- foldRight (monoid)
- collect
- flatten / [join] - flatten one level
- stream
- toStreamable
- toOptional
When bind / flatMap / map / filter is called Cyclops will attempt to interpret the bind method via the registered Comprehender implementations. If none is found for the wrapped Monads type, the InvokeDyanamicComprehender will be used, that will attempt to execute the current method (bind / flatMap / map / filter) by making some assumptions about likely target method names & number of parameters. Dynamic proxies will be used to convert from JDK types to foreign functional interfaces.
Provide a way to abstract common operations across all Monad types. Monad support is extensible via Service Loader mechnanisms. Custom Comprehender implementations can easily be added