Constructor and Description |
---|
Instances() |
Modifier and Type | Method and Description |
---|---|
static InstanceDefinitions<Witness.set> |
definitions() |
static <T> Foldable<Witness.set> |
foldable()
int sum = Sets.foldable()
.foldLeft(0, (a,b)->a+b, SetX.widen(Arrays.asSet(1,2,3,4)));
//10
|
static <T,R> Functor<Witness.set> |
functor()
Transform a set, mulitplying every element by 2
|
static <T,R> Monad<Witness.set> |
monad()
import static com.aol.cyclops2.hkt.jdk.SetX.widen;
SetX<Integer> set = Sets.monad()
.flatMap(i->widen(SetX.range(0,i)), widen(Arrays.asSet(1,2,3)))
.convert(SetX::narrowK3);
|
static <T> MonadPlus<Witness.set> |
monadPlus()
SetX<Integer> set = Sets.<Integer>monadPlus()
.plus(SetX.widen(Arrays.asSet()), SetX.widen(Arrays.asSet(10)))
.convert(SetX::narrowK3);
//Arrays.asSet(10))
|
static <T> MonadPlus<Witness.set> |
monadPlus(Monoid<SetX<T>> m)
Monoid<SetX<Integer>> m = Monoid.of(SetX.widen(Arrays.asSet()), (a,b)->a.isEmpty() ? b : a);
SetX<Integer> set = Sets.<Integer>monadPlus(m)
.plus(SetX.widen(Arrays.asSet(5)), SetX.widen(Arrays.asSet(10)))
.convert(SetX::narrowK3);
//Arrays.asSet(5))
|
static <T,R> MonadRec<Witness.set> |
monadRec() |
static <T,R> MonadZero<Witness.set> |
monadZero()
SetX<String> set = Sets.unit()
.unit("hello")
.applyHKT(h->Sets.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(SetX::narrowK3);
//Arrays.asSet("hello"));
|
static <T> SetX<T> |
narrow(Higher<Witness.set,T> completableSet)
Convert the HigherKindedType definition for a Set into
|
static <T> SetX<T> |
narrowK(Higher<Witness.set,T> future)
Convert the raw Higher Kinded Type for SetType types into the SetType type definition class
|
static <C2,T> Traverse<Witness.set> |
traverse() |
static Unfoldable<Witness.set> |
unfoldable() |
static <T> Pure<Witness.set> |
unit()
SetX<String> set = Sets.unit()
.unit("hello")
.convert(SetX::narrowK3);
//Arrays.asSet("hello"))
|
static <C2,T> Higher<C2,Higher<Witness.set,T>> |
widen2(Higher<C2,SetX<T>> flux)
Widen a SetType nest inside another HKT encoded type
|
static <T,R> Applicative<Witness.set> |
zippingApplicative()
import static com.aol.cyclops2.hkt.jdk.SetX.widen;
import static com.aol.cyclops2.util.function.Lambda.l1;
import static java.util.Arrays.asSet;
Sets.zippingApplicative()
.ap(widen(asSet(l1(this::multiplyByTwo))),widen(asSet(1,2,3)));
//[2,4,6]
|
public static InstanceDefinitions<Witness.set> definitions()
public static Unfoldable<Witness.set> unfoldable()
public static <T,R> Functor<Witness.set> functor()
SetX<Integer> set = Sets.functor().map(i->i*2, SetX.widen(Arrays.asSet(1,2,3));
//[2,4,6]
An example fluent api working with Sets
SetX<Integer> set = Sets.unit()
.unit("hello")
.applyHKT(h->Sets.functor().map((String v) ->v.length(), h))
.convert(SetX::narrowK3);
public static <T> Pure<Witness.set> unit()
SetX<String> set = Sets.unit()
.unit("hello")
.convert(SetX::narrowK3);
//Arrays.asSet("hello"))
public static <T,R> Applicative<Witness.set> zippingApplicative()
import static com.aol.cyclops2.hkt.jdk.SetX.widen;
import static com.aol.cyclops2.util.function.Lambda.l1;
import static java.util.Arrays.asSet;
Sets.zippingApplicative()
.ap(widen(asSet(l1(this::multiplyByTwo))),widen(asSet(1,2,3)));
//[2,4,6]
Example fluent API
SetX<Function<Integer,Integer>> setFn =Sets.unit()
.unit(Lambda.l1((Integer i) ->i*2))
.convert(SetX::narrowK3);
SetX<Integer> set = Sets.unit()
.unit("hello")
.applyHKT(h->Sets.functor().map((String v) ->v.length(), h))
.applyHKT(h->Sets.zippingApplicative().ap(setFn, h))
.convert(SetX::narrowK3);
//Arrays.asSet("hello".length()*2))
public static <T,R> Monad<Witness.set> monad()
import static com.aol.cyclops2.hkt.jdk.SetX.widen;
SetX<Integer> set = Sets.monad()
.flatMap(i->widen(SetX.range(0,i)), widen(Arrays.asSet(1,2,3)))
.convert(SetX::narrowK3);
Example fluent API
SetX<Integer> set = Sets.unit()
.unit("hello")
.applyHKT(h->Sets.monad().flatMap((String v) ->Sets.unit().unit(v.length()), h))
.convert(SetX::narrowK3);
//Arrays.asSet("hello".length())
public static <T,R> MonadRec<Witness.set> monadRec()
public static <T,R> MonadZero<Witness.set> monadZero()
SetX<String> set = Sets.unit()
.unit("hello")
.applyHKT(h->Sets.monadZero().filter((String t)->t.startsWith("he"), h))
.convert(SetX::narrowK3);
//Arrays.asSet("hello"));
public static <T> MonadPlus<Witness.set> monadPlus()
SetX<Integer> set = Sets.<Integer>monadPlus()
.plus(SetX.widen(Arrays.asSet()), SetX.widen(Arrays.asSet(10)))
.convert(SetX::narrowK3);
//Arrays.asSet(10))
public static <T> MonadPlus<Witness.set> monadPlus(Monoid<SetX<T>> m)
Monoid<SetX<Integer>> m = Monoid.of(SetX.widen(Arrays.asSet()), (a,b)->a.isEmpty() ? b : a);
SetX<Integer> set = Sets.<Integer>monadPlus(m)
.plus(SetX.widen(Arrays.asSet(5)), SetX.widen(Arrays.asSet(10)))
.convert(SetX::narrowK3);
//Arrays.asSet(5))
m
- Monoid to use for combining Setspublic static <C2,T> Traverse<Witness.set> traverse()
public static <T> Foldable<Witness.set> foldable()
int sum = Sets.foldable()
.foldLeft(0, (a,b)->a+b, SetX.widen(Arrays.asSet(1,2,3,4)));
//10
public static <C2,T> Higher<C2,Higher<Witness.set,T>> widen2(Higher<C2,SetX<T>> flux)
flux
- HTK encoded type containing a Set to widenpublic static <T> SetX<T> narrowK(Higher<Witness.set,T> future)
future
- HKT encoded set into a SetTypepublic static <T> SetX<T> narrow(Higher<Witness.set,T> completableSet)
Set
- Type Constructor to convert back into narrowed type