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