Skip to content

Type Interfaces : MonadicValue1

johnmcclean-aol edited this page Nov 22, 2016 · 1 revision

The MonadicValue1 interface

A MonadicValue1 represents a Value with a single type parameter (e.g. a Maybe or FutureW opposed to an Xor or Try) that is also a monad.

In cyclops-react it has the following methods

  • flatMap : flattening transformation operation
  • combineEager : eagerly combine two Monadic values
  • flatMapIterable : flatMap this MonadicValue with an Iterable type taking the first value if the Iterable has more than 1
  • flatMapPublisher : flatMap this MonadicValue with an Publisher type taking the first value if the Publisher has more than 1

Examples

Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
  Maybe.of(10).combineEager(add,Maybe.none());
  //Maybe[10]
  
  Maybe.none().combineEager(add,Maybe.of(10));
  //Maybe[10]
  
  Maybe.none().combineEager(add,Maybe.none());
  //Maybe.none()
  
  Maybe.of(10).combineEager(add,Maybe.of(10));
  //Maybe[20]
  
  Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
  Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
  //Maybe[10]

Implementations

Eval, FeatureToggle, Maybe

Clone this wiki locally