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