public class FutureWInstances
extends java.lang.Object
Constructor and Description |
---|
FutureWInstances() |
Modifier and Type | Method and Description |
---|---|
static <T,R> Applicative<FutureType.µ> |
applicative()
import static com.aol.cyclops.hkt.jdk.FutureType.widen;
import static com.aol.cyclops.util.function.Lambda.l1;
import static java.util.Arrays.asFutureW;
FutureWs.zippingApplicative()
.ap(widen(asFutureW(l1(this::multiplyByTwo))),widen(asFutureW(1,2,3)));
//[2,4,6]
|
static <T> Comonad<FutureType.µ> |
comonad() |
static <T> Foldable<FutureType.µ> |
foldable()
int sum = FutureWs.foldable()
.foldLeft(0, (a,b)->a+b, FutureType.widen(FutureW.ofResult(4)));
//4
|
static <T,R> Functor<FutureType.µ> |
functor()
Transform a future, mulitplying every element by 2
|
static <T,R> Monad<FutureType.µ> |
monad()
import static com.aol.cyclops.hkt.jdk.FutureType.widen;
FutureType<Integer> future = FutureWs.monad()
.flatMap(i->widen(FutureW.ofResult(0)), widen(FutureW.ofResult(2)))
.convert(FutureType::narrowK);
|
static <T> MonadPlus<FutureType.µ> |
monadPlus()
FutureType<Integer> future = FutureWs.<Integer>monadPlus()
.plus(FutureType.widen(FutureW.future()), FutureType.widen(FutureW.ofResult(10)))
.convert(FutureType::narrowK);
//FutureW[10]
|
static <T> MonadPlus<FutureType.µ> |
monadPlus(com.aol.cyclops.Monoid<FutureType<T>> m)
Monoid<FutureType<Integer>> m = Monoid.of(FutureType.widen(FutureW.future()()), (a,b)->a.isDone() ? b : a);
FutureType<Integer> future = FutureWs.<Integer>monadPlus(m)
.plus(FutureType.widen(FutureW.ofResult(5)), FutureType.widen(FutureW.ofResult(10)))
.convert(FutureType::narrowK);
//FutureW(5)
|
static <T,R> MonadZero<FutureType.µ> |
monadZero()
FutureType<String> future = FutureWs.unit()
.unit("hello")
.then(h->FutureWs.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(FutureType::narrowK);
//FutureW["hello"]
|
static <C2,T> Traverse<FutureType.µ> |
traverse() |
static <T> Unit<FutureType.µ> |
unit()
FutureType<String> future = FutureWs.unit()
.unit("hello")
.convert(FutureType::narrowK);
//FutureW("hello")
|
public static <T,R> Functor<FutureType.µ> functor()
FutureType<Integer> future = FutureWs.functor().map(i->i*2, FutureType.widen(FutureW.ofResult(2));
//[4]
An example fluent api working with FutureWs
FutureType<Integer> future = FutureWs.unit()
.unit("hello")
.then(h->FutureWs.functor().map((String v) ->v.length(), h))
.convert(FutureType::narrowK);
public static <T> Unit<FutureType.µ> unit()
FutureType<String> future = FutureWs.unit()
.unit("hello")
.convert(FutureType::narrowK);
//FutureW("hello")
public static <T,R> Applicative<FutureType.µ> applicative()
import static com.aol.cyclops.hkt.jdk.FutureType.widen;
import static com.aol.cyclops.util.function.Lambda.l1;
import static java.util.Arrays.asFutureW;
FutureWs.zippingApplicative()
.ap(widen(asFutureW(l1(this::multiplyByTwo))),widen(asFutureW(1,2,3)));
//[2,4,6]
Example fluent API
FutureType<Function<Integer,Integer>> futureFn =FutureWs.unit()
.unit(Lambda.l1((Integer i) ->i*2))
.convert(FutureType::narrowK);
FutureType<Integer> future = FutureWs.unit()
.unit("hello")
.then(h->FutureWs.functor().map((String v) ->v.length(), h))
.then(h->FutureWs.applicative().ap(futureFn, h))
.convert(FutureType::narrowK);
//FutureW("hello".length()*2))
public static <T,R> Monad<FutureType.µ> monad()
import static com.aol.cyclops.hkt.jdk.FutureType.widen;
FutureType<Integer> future = FutureWs.monad()
.flatMap(i->widen(FutureW.ofResult(0)), widen(FutureW.ofResult(2)))
.convert(FutureType::narrowK);
Example fluent API
FutureType<Integer> future = FutureWs.unit()
.unit("hello")
.then(h->FutureWs.monad().flatMap((String v) ->FutureWs.unit().unit(v.length()), h))
.convert(FutureType::narrowK);
//FutureW("hello".length())
public static <T,R> MonadZero<FutureType.µ> monadZero()
FutureType<String> future = FutureWs.unit()
.unit("hello")
.then(h->FutureWs.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(FutureType::narrowK);
//FutureW["hello"]
public static <T> MonadPlus<FutureType.µ> monadPlus()
FutureType<Integer> future = FutureWs.<Integer>monadPlus()
.plus(FutureType.widen(FutureW.future()), FutureType.widen(FutureW.ofResult(10)))
.convert(FutureType::narrowK);
//FutureW[10]
public static <T> MonadPlus<FutureType.µ> monadPlus(com.aol.cyclops.Monoid<FutureType<T>> m)
Monoid<FutureType<Integer>> m = Monoid.of(FutureType.widen(FutureW.future()()), (a,b)->a.isDone() ? b : a);
FutureType<Integer> future = FutureWs.<Integer>monadPlus(m)
.plus(FutureType.widen(FutureW.ofResult(5)), FutureType.widen(FutureW.ofResult(10)))
.convert(FutureType::narrowK);
//FutureW(5)
m
- Monoid to use for combining FutureWspublic static <C2,T> Traverse<FutureType.µ> traverse()
public static <T> Foldable<FutureType.µ> foldable()
int sum = FutureWs.foldable()
.foldLeft(0, (a,b)->a+b, FutureType.widen(FutureW.ofResult(4)));
//4
public static <T> Comonad<FutureType.µ> comonad()