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