Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.data
Class Enumerator<A>

java.lang.Object
  extended by fj.data.Enumerator<A>

public final class Enumerator<A>
extends Object

Abstracts 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 for plus, otherwise a default is implemented using the given successor/predecessor implementations.

For any enumerator e, the following laws must satisfy:


Field Summary
static Enumerator<BigDecimal> bigdecimalEnumerator
          An enumerator for BigDecimal.
static Enumerator<BigInteger> bigintEnumerator
          An enumerator for BigInteger.
static Enumerator<Boolean> booleanEnumerator
          An enumerator for boolean.
static Enumerator<Byte> byteEnumerator
          An enumerator for byte.
static Enumerator<Character> charEnumerator
          An enumerator for char.
static Enumerator<Double> doubleEnumerator
          An enumerator for double.
static Enumerator<Float> floatEnumerator
          An enumerator for float.
static Enumerator<Integer> intEnumerator
          An enumerator for int.
static Enumerator<Long> longEnumerator
          An enumerator for long.
static Enumerator<Natural> naturalEnumerator
          An enumerator for Natural
static Enumerator<Ordering> orderingEnumerator
          An enumerator for Ordering.
static Enumerator<Short> shortEnumerator
          An enumerator for short.
 
Method Summary
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<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<Long,Option<A>>> plus()
          Returns a function that moves a value along the enumerator a given number of times.
 F<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>> plus(long l)
          Returns a function that 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.
<B> Enumerator<B>
xmap(F<A,B> f, F<B,A> g)
          Invariant functor map over this enumerator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

booleanEnumerator

public static final Enumerator<Boolean> booleanEnumerator
An enumerator for boolean.


byteEnumerator

public static final Enumerator<Byte> byteEnumerator
An enumerator for byte.


charEnumerator

public static final Enumerator<Character> charEnumerator
An enumerator for char.


doubleEnumerator

public static final Enumerator<Double> doubleEnumerator
An enumerator for double.


floatEnumerator

public static final Enumerator<Float> floatEnumerator
An enumerator for float.


intEnumerator

public static final Enumerator<Integer> intEnumerator
An enumerator for int.


bigintEnumerator

public static final Enumerator<BigInteger> bigintEnumerator
An enumerator for BigInteger.


bigdecimalEnumerator

public static final Enumerator<BigDecimal> bigdecimalEnumerator
An enumerator for BigDecimal.


longEnumerator

public static final Enumerator<Long> longEnumerator
An enumerator for long.


shortEnumerator

public static final Enumerator<Short> shortEnumerator
An enumerator for short.


orderingEnumerator

public static final Enumerator<Ordering> orderingEnumerator
An enumerator for Ordering.


naturalEnumerator

public static final Enumerator<Natural> naturalEnumerator
An enumerator for Natural

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<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<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.

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<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. The plus function is derived from the successor and predecessor.

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.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.