Skip to content

Type Interfaces : BiFunctor

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

The BiFunctor interface

A BiFunctor can transform data with two type parameters representing two potential types into another two types (e.g. A Map has a type for it's Keys and Values, we could transform both, an Xor has a Primary and Secondary type only one of which is present but we can provide mapping functions for both and execute the function against the present type).

In cyclops-react it has the following methods

  • bimap : transforms the data using the provided transformation Function
  • bipeek : allows us to consume the current elements without transforming them (e.g. to print to the console)
  • bitrampoline : transforms the data using a trampoline for stack-less recursion
  • bicast : cast elements from one type to another

Example

Ior<FileNotFoundException,Integer> success = Ior.primary(10);
Ior<RuntimeException,Integer> mapped = success.bimap(e->new RuntimeException(), d->d+1);
Ior#Primary[11]

MapX<String,Integer> map = MapXs.of("a",1,"b",2);
MapX<Integer,String> mapped  = map.bimap(k->k.length(),v->"value"+v);

Implementations

Ior<ST,PT>, MapX<K,V>, PMapX<K,V>, Xor<ST,PT>

Clone this wiki locally