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