-
Notifications
You must be signed in to change notification settings - Fork 51
Wrappers : Functor
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.
com.aol.cyclops.lambda.monads.Functor is a generic interface that wraps around Functor implementations (classes such as java.util.Stream that implement a transforming map method - to be 100% strict Functors should also obey the functor laws, but for the wrapper to work, the Functor class need only implement a transforming map method).
Functors can be coerced to the generic Functor interface via
- AsFunctor.asFunctor
- As.asFunctor
com.aol.cyclops.lambda.monads.Functor provides
- map (java.util.Function)
- peek (java.util.Consumer)
The Functor interface will attempt to call the map method method on the underlying functor via the registered Cyclops Comprehenders. If no Comprehender for the underlying Functor type, Cyclops will attempt to call the map method via InvokeDynamic (making some assumptions about the method name), and wrapping the java.util.Function in an appropriate dynamic proxy.
This allows more generic code to be written, for example functions or methods that can accept any Functor.