Skip to content

Type Interfaces : ApplicativeFunctor

johnmcclean-aol edited this page Nov 22, 2016 · 2 revisions

The ApplicativeFunctor interface

An ApplicativeFunctor can be used to combine values inside wrapped types by applying a function.

In cyclops-react it has the following methods

  • combine : lazily combines the current ApplicativeFunctor with another Value or Combiner/ ApplicativeFunctor type via a user supplied function
  • zip : lazily combines the current ApplicativeFunctor with another Iterable or Publisher using the user supplied function
  • applyFunctions : allows us to embed a method reference or function with a varying number of parameters inside the current Applicative partially applying it's current value as the first parameter. Subsequent parameters can be added via the ap method. When all parameters have been added the function is eagerly applied.

Examples

FutureW.ofSupplier(this::loadData,exec)
       .combine(Maybe.just(10),(a,b)->a+b))//asynchronously apply the adding function when loadData completes

FutureW.ofSupplier(this::loadData,exec)
       .applyFunctions()
       .ap(Semigroups.intMult)
       .ap(Optional.of(20)) //block until loadData completes, multiply the result by 20.
     

Implementations

CompletableFutureTValue, Eval.Module.Always, Eval.Module.Later, EvalTValue, FeatureToggle.Disabled, FeatureToggle.Enabled, FutureW, FutureWTValue, Ior.Both, Ior.Primary, Ior.Secondary, LazyImmutable, Maybe.Just, Maybe.Lazy, Maybe.Nothing, MaybeTValue, OptionalTValue, Try.Failure, Try.Success, TryTValue, Xor.Primary, Xor.Secondary, XorTValue

Clone this wiki locally