Constructor and Description |
---|
Instances() |
Modifier and Type | Method and Description |
---|---|
static <T> Foldable<DequeX.µ> |
foldable()
int sum = Deques.foldable()
.foldLeft(0, (a,b)->a+b, DequeX.of(1,2,3,4)));
//10
|
static <T,R> Functor<DequeX.µ> |
functor()
Transform a list, mulitplying every element by 2
|
static <T,R> Monad<DequeX.µ> |
monad()
import static com.aol.cyclops.hkt.jdk.DequeX.widen;
DequeX<Integer> list = Deques.monad()
.flatMap(i->widen(DequeX.range(0,i)), widen(DequeX.of(1,2,3)))
.convert(DequeX::narrowK);
|
static <T> MonadPlus<DequeX.µ> |
monadPlus()
DequeX<Integer> list = Deques.<Integer>monadPlus()
.plus(DequeX.of()), DequeX.of(10)))
.convert(DequeX::narrowK);
//DequeX.of(10))
|
static <T> MonadPlus<DequeX.µ> |
monadPlus(Monoid<DequeX<T>> m)
Monoid<DequeX<Integer>> m = Monoid.of(DequeX.of()), (a,b)->a.isEmpty() ? b : a);
DequeX<Integer> list = Deques.<Integer>monadPlus(m)
.plus(DequeX.of(5)), DequeX.of(10)))
.convert(DequeX::narrowK);
//DequeX.of(5))
|
static <T,R> MonadZero<DequeX.µ> |
monadZero()
DequeX<String> list = Deques.unit()
.unit("hello")
.transform(h->Deques.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(DequeX::narrowK);
//DequeX.of("hello"));
|
static <C2,T> Traverse<DequeX.µ> |
traverse() |
static <T> Pure<DequeX.µ> |
unit()
DequeX<String> list = Deques.unit()
.unit("hello")
.convert(DequeX::narrowK);
//DequeX.of("hello"))
|
static <T,R> Applicative<DequeX.µ> |
zippingApplicative()
import static com.aol.cyclops.hkt.jdk.DequeX.widen;
import static com.aol.cyclops.util.function.Lambda.l1;
import static java.util.DequeX.of;
Deques.zippingApplicative()
.ap(widen(asDeque(l1(this::multiplyByTwo))),widen(asDeque(1,2,3)));
//[2,4,6]
|
public static <T,R> Functor<DequeX.µ> functor()
DequeX<Integer> list = Deques.functor().map(i->i*2, DequeX.of(1,2,3));
//[2,4,6]
An example fluent api working with Deques
DequeX<Integer> list = Deques.unit()
.unit("hello")
.transform(h->Deques.functor().map((String v) ->v.length(), h))
.convert(DequeX::narrowK);
public static <T> Pure<DequeX.µ> unit()
DequeX<String> list = Deques.unit()
.unit("hello")
.convert(DequeX::narrowK);
//DequeX.of("hello"))
public static <T,R> Applicative<DequeX.µ> zippingApplicative()
import static com.aol.cyclops.hkt.jdk.DequeX.widen;
import static com.aol.cyclops.util.function.Lambda.l1;
import static java.util.DequeX.of;
Deques.zippingApplicative()
.ap(widen(asDeque(l1(this::multiplyByTwo))),widen(asDeque(1,2,3)));
//[2,4,6]
Example fluent API
DequeX<Function<Integer,Integer>> listFn =Deques.unit()
.unit(Lambda.l1((Integer i) ->i*2))
.convert(DequeX::narrowK);
DequeX<Integer> list = Deques.unit()
.unit("hello")
.transform(h->Deques.functor().map((String v) ->v.length(), h))
.transform(h->Deques.zippingApplicative().ap(listFn, h))
.convert(DequeX::narrowK);
//DequeX.of("hello".length()*2))
public static <T,R> Monad<DequeX.µ> monad()
import static com.aol.cyclops.hkt.jdk.DequeX.widen;
DequeX<Integer> list = Deques.monad()
.flatMap(i->widen(DequeX.range(0,i)), widen(DequeX.of(1,2,3)))
.convert(DequeX::narrowK);
Example fluent API
DequeX<Integer> list = Deques.unit()
.unit("hello")
.transform(h->Deques.monad().flatMap((String v) ->Deques.unit().unit(v.length()), h))
.convert(DequeX::narrowK);
//DequeX.of("hello".length())
public static <T,R> MonadZero<DequeX.µ> monadZero()
DequeX<String> list = Deques.unit()
.unit("hello")
.transform(h->Deques.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(DequeX::narrowK);
//DequeX.of("hello"));
public static <T> MonadPlus<DequeX.µ> monadPlus()
DequeX<Integer> list = Deques.<Integer>monadPlus()
.plus(DequeX.of()), DequeX.of(10)))
.convert(DequeX::narrowK);
//DequeX.of(10))
public static <T> MonadPlus<DequeX.µ> monadPlus(Monoid<DequeX<T>> m)
Monoid<DequeX<Integer>> m = Monoid.of(DequeX.of()), (a,b)->a.isEmpty() ? b : a);
DequeX<Integer> list = Deques.<Integer>monadPlus(m)
.plus(DequeX.of(5)), DequeX.of(10)))
.convert(DequeX::narrowK);
//DequeX.of(5))
m
- Monoid to use for combining Dequespublic static <C2,T> Traverse<DequeX.µ> traverse()