Skip to content
johnmcclean-aol edited this page Feb 24, 2016 · 3 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 Monad Wrapper

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)

Wrapping (coercing) to Monad

Monads can be coerced to the generic Monad interface via

  • AsMonad.asMonad
  • As.asMonad

Monad operations

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

Behaviour when bind / flatMap / map / filter is called on a coerced Monad

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.

Rationale

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

Clone this wiki locally