Skip to content
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.

screen shot 2016-02-22 at 8 44 42 pm

The Functor Wrapper

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).

Wrapping (coercing) to Functor

Functors can be coerced to the generic Functor interface via

  • AsFunctor.asFunctor
  • As.asFunctor

Functor operations

com.aol.cyclops.lambda.monads.Functor provides

  • map (java.util.Function)
  • peek (java.util.Consumer)

Behaviour when map or peek is called

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.

Rationale

This allows more generic code to be written, for example functions or methods that can accept any Functor.

Clone this wiki locally