Package fj.data

Class Enumerator<A>


  • public final class Enumerator<A>
    extends java.lang.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:

    • 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 Detail

      • successor

        private final F<A,​Option<A>> successor
      • predecessor

        private final F<A,​Option<A>> predecessor
      • order

        private final Ord<A> order
      • plus

        private final F<A,​F<java.lang.Long,​Option<A>>> plus
      • booleanEnumerator

        public static final Enumerator<java.lang.Boolean> booleanEnumerator
        An enumerator for boolean.
      • byteEnumerator

        public static final Enumerator<java.lang.Byte> byteEnumerator
        An enumerator for byte.
      • charEnumerator

        public static final Enumerator<java.lang.Character> charEnumerator
        An enumerator for char.
      • doubleEnumerator

        public static final Enumerator<java.lang.Double> doubleEnumerator
        An enumerator for double.
      • floatEnumerator

        public static final Enumerator<java.lang.Float> floatEnumerator
        An enumerator for float.
      • intEnumerator

        public static final Enumerator<java.lang.Integer> intEnumerator
        An enumerator for int.
      • bigintEnumerator

        public static final Enumerator<java.math.BigInteger> bigintEnumerator
        An enumerator for BigInteger.
      • bigdecimalEnumerator

        public static final Enumerator<java.math.BigDecimal> bigdecimalEnumerator
        An enumerator for BigDecimal.
      • longEnumerator

        public static final Enumerator<java.lang.Long> longEnumerator
        An enumerator for long.
      • shortEnumerator

        public static final Enumerator<java.lang.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<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. 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.