Package fj.data
Class Enumerator<A>
- java.lang.Object
-
- fj.data.Enumerator<A>
-
public final class Enumerator<A> extends java.lang.ObjectAbstracts over a type that may have a successor and/or predecessor value. This implies ordering for that type. A user may construct an enumerator with an optimised version forplus, otherwise a default is implemented using the given successor/predecessor implementations. For any enumerator e, the following laws must satisfy:forall a. e.successor(a).forall(\t -> e.predecessor(t).forall(\z -> z == a))forall a. e.predecessor(a).forall(\t -> e.successor(t).forall(\z -> z == a))e.max().forall(\t -> e.successor(t).isNone)e.min().forall(\t -> e.predecessor(t).isNone)forall a n. e.plus(a, 0) == Some(a)forall a n | n > 0. e.plus(a, n) == e.plus(a, n - 1)forall a n | n < 0. e.plus(a, n) == e.plus(a, n + 1)
- Version:
- %build.number%
-
-
Field Summary
Fields Modifier and Type Field Description static Enumerator<java.math.BigDecimal>bigdecimalEnumeratorAn enumerator forBigDecimal.static Enumerator<java.math.BigInteger>bigintEnumeratorAn enumerator forBigInteger.static Enumerator<java.lang.Boolean>booleanEnumeratorAn enumerator forboolean.static Enumerator<java.lang.Byte>byteEnumeratorAn enumerator forbyte.static Enumerator<java.lang.Character>charEnumeratorAn enumerator forchar.static Enumerator<java.lang.Double>doubleEnumeratorAn enumerator fordouble.static Enumerator<java.lang.Float>floatEnumeratorAn enumerator forfloat.static Enumerator<java.lang.Integer>intEnumeratorAn enumerator forint.static Enumerator<java.lang.Long>longEnumeratorAn enumerator forlong.private Option<A>maxprivate Option<A>minstatic Enumerator<Natural>naturalEnumeratorAn enumerator forNaturalprivate Ord<A>orderstatic Enumerator<Ordering>orderingEnumeratorAn enumerator forOrdering.private F<A,F<java.lang.Long,Option<A>>>plusprivate F<A,Option<A>>predecessorstatic Enumerator<java.lang.Short>shortEnumeratorAn enumerator forshort.private F<A,Option<A>>successor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A> Enumerator<A>enumerator(F<A,Option<A>> successor, F<A,Option<A>> predecessor, Option<A> max, Option<A> min, Ord<A> order)Construct an enumerator.static <A> Enumerator<A>enumerator(F<A,Option<A>> successor, F<A,Option<A>> predecessor, Option<A> max, Option<A> min, Ord<A> order, F<A,F<java.lang.Long,Option<A>>> plus)Construct an enumerator.Option<A>max()Returns the maximum value for this enumerator if there is one.Option<A>min()Returns the minimum value for this enumerator if there is one.Ord<A>order()Returns the ordering for the enumerator.F<A,F<java.lang.Long,Option<A>>>plus()Returns a function that moves a value along the enumerator a given number of times.F<A,Option<A>>plus(long l)Returns a function that moves a value along the enumerator a given number of times.F<java.lang.Long,Option<A>>plus(A a)Returns a function that moves a value along the enumerator a given number of times.Option<A>plus(A a, long l)Moves a value along the enumerator a given number of times.F<A,Option<A>>predecessor()Returns the potential predecessor of a value for this enumerator in curried form.Option<A>predecessor(A a)Returns the potential predecessor of a value for this enumerator.Enumerator<A>setMax(Option<A> max)Create a new enumerator with the given maximum value.Enumerator<A>setMin(Option<A> min)Create a new enumerator with the given minimum value.F<A,Option<A>>successor()Returns the potential successor of a value for this enumerator in curried form.Option<A>successor(A a)Returns the potential successor of a value for this enumerator.Stream<A>toStream(A a)Returns a stream of the values from this enumerator, starting at the given value, counting up.Stream<A>toStream(Bounded<A> bounded)Returns a stream of the values from this enumerator, starting at the min of given Bounded, ending at the max, counting up.<B> Enumerator<B>xmap(F<A,B> f, F<B,A> g)Invariant functor map over this enumerator.
-
-
-
Field Detail
-
booleanEnumerator
public static final Enumerator<java.lang.Boolean> booleanEnumerator
An enumerator forboolean.
-
byteEnumerator
public static final Enumerator<java.lang.Byte> byteEnumerator
An enumerator forbyte.
-
charEnumerator
public static final Enumerator<java.lang.Character> charEnumerator
An enumerator forchar.
-
doubleEnumerator
public static final Enumerator<java.lang.Double> doubleEnumerator
An enumerator fordouble.
-
floatEnumerator
public static final Enumerator<java.lang.Float> floatEnumerator
An enumerator forfloat.
-
intEnumerator
public static final Enumerator<java.lang.Integer> intEnumerator
An enumerator forint.
-
bigintEnumerator
public static final Enumerator<java.math.BigInteger> bigintEnumerator
An enumerator forBigInteger.
-
bigdecimalEnumerator
public static final Enumerator<java.math.BigDecimal> bigdecimalEnumerator
An enumerator forBigDecimal.
-
longEnumerator
public static final Enumerator<java.lang.Long> longEnumerator
An enumerator forlong.
-
shortEnumerator
public static final Enumerator<java.lang.Short> shortEnumerator
An enumerator forshort.
-
orderingEnumerator
public static final Enumerator<Ordering> orderingEnumerator
An enumerator forOrdering.
-
naturalEnumerator
public static final Enumerator<Natural> naturalEnumerator
An enumerator forNatural
-
-
Method Detail
-
successor
public F<A,Option<A>> successor()
Returns the potential successor of a value for this enumerator in curried form.- Returns:
- The potential successor of a value for this enumerator in curried form.
-
successor
public Option<A> successor(A a)
Returns the potential successor of a value for this enumerator.- Parameters:
a- The value to return the successor of.- Returns:
- The potential successor of a value for this enumerator.
-
predecessor
public F<A,Option<A>> predecessor()
Returns the potential predecessor of a value for this enumerator in curried form.- Returns:
- The potential predecessor of a value for this enumerator in curried form.
-
predecessor
public Option<A> predecessor(A a)
Returns the potential predecessor of a value for this enumerator.- Parameters:
a- The value to return the predecessor of.- Returns:
- The potential predecessor of a value for this enumerator.
-
max
public Option<A> max()
Returns the maximum value for this enumerator if there is one.- Returns:
- The maximum value for this enumerator if there is one.
-
min
public Option<A> min()
Returns the minimum value for this enumerator if there is one.- Returns:
- The minimum value for this enumerator if there is one.
-
plus
public F<A,F<java.lang.Long,Option<A>>> plus()
Returns a function that moves a value along the enumerator a given number of times.- Returns:
- A function that moves a value along the enumerator a given number of times.
-
plus
public F<java.lang.Long,Option<A>> plus(A a)
Returns a function that moves a value along the enumerator a given number of times.- Parameters:
a- The value to begin moving along from.- Returns:
- A function that moves a value along the enumerator a given number of times.
-
plus
public F<A,Option<A>> plus(long l)
Returns a function that moves a value along the enumerator a given number of times.- Parameters:
l- The number of times to move along the enumerator.- Returns:
- A function that moves a value along the enumerator a given number of times.
-
plus
public Option<A> plus(A a, long l)
Moves a value along the enumerator a given number of times.- Parameters:
a- The value to begin moving along from.l- The number of times to move along the enumerator.- Returns:
- A potential value after having moved the given number of times.
-
order
public Ord<A> order()
Returns the ordering for the enumerator.- Returns:
- The ordering for the enumerator.
-
xmap
public <B> Enumerator<B> xmap(F<A,B> f, F<B,A> g)
Invariant functor map over this enumerator.- Parameters:
f- The covariant map.g- The contra-variant map.- Returns:
- An enumerator after the given functions are applied.
-
toStream
public Stream<A> toStream(A a)
Returns a stream of the values from this enumerator, starting at the given value, counting up.- Parameters:
a- A value at which to begin the stream.- Returns:
- a stream of the values from this enumerator, starting at the given value, counting up.
-
toStream
public Stream<A> toStream(Bounded<A> bounded)
Returns a stream of the values from this enumerator, starting at the min of given Bounded, ending at the max, counting up.- Parameters:
bounded- A value at which to begin the stream.- Returns:
- a stream of the values from this enumerator, cut by bounded, counting up.
-
setMin
public Enumerator<A> setMin(Option<A> min)
Create a new enumerator with the given minimum value.- Parameters:
min- A minimum value.- Returns:
- A new enumerator identical to this one, but with the given minimum value.
-
setMax
public Enumerator<A> setMax(Option<A> max)
Create a new enumerator with the given maximum value.- Parameters:
max- A maximum value.- Returns:
- A new enumerator identical to this one, but with the given maximum value.
-
enumerator
public static <A> Enumerator<A> enumerator(F<A,Option<A>> successor, F<A,Option<A>> predecessor, Option<A> max, Option<A> min, Ord<A> order, F<A,F<java.lang.Long,Option<A>>> plus)
Construct an enumerator. `- Parameters:
successor- The successor function.predecessor- The predecessor function.max- The potential maximum value.min- The potential minimum value.order- The ordering for the type.plus- The function to move the enumeration a given number of times. This may be supplied for a performance enhancement for certain types.- Returns:
- An enumerator with the given values.
-
enumerator
public static <A> Enumerator<A> enumerator(F<A,Option<A>> successor, F<A,Option<A>> predecessor, Option<A> max, Option<A> min, Ord<A> order)
Construct an enumerator. Theplusfunction is derived from thesuccessorandpredecessor.- Parameters:
successor- The successor function.predecessor- The predecessor function.max- The potential maximum value.min- The potential minimum value.order- The ordering for the type.- Returns:
- An enumerator with the given values.
-
-