Class Digit<V,​A>

  • Direct Known Subclasses:
    Four, One, Three, Two

    public abstract class Digit<V,​A>
    extends java.lang.Object
    A digit is a vector of 1-4 elements. Serves as a pointer to the prefix or suffix of a finger tree.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Measured<V,​A> m  
    • Constructor Summary

      Constructors 
      Constructor Description
      Digit​(Measured<V,​A> m)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract <B> B foldLeft​(F<B,​F<A,​B>> f, B z)
      Folds this digit to the left using the given function and the given initial value.
      abstract <B> B foldRight​(F<A,​F<B,​B>> f, B z)
      Folds this digit to the right using the given function and the given initial value.
      (package private) Option<Digit<V,​A>> init()  
      abstract int length()  
      abstract P2<java.lang.Integer,​A> lookup​(F<V,​java.lang.Integer> o, int i)  
      <B> Digit<V,​B> map​(F<A,​B> f, Measured<V,​B> m)
      Maps a function across the elements of this digit, measuring with the given measurement.
      abstract <B> B match​(F<One<V,​A>,​B> one, F<Two<V,​A>,​B> two, F<Three<V,​A>,​B> three, F<Four<V,​A>,​B> four)
      Structural pattern matching on digits.
      V measure()
      Returns the sum of the measurements of this digit according to the monoid.
      (package private) Measured<V,​A> measured()  
      A reduceLeft​(F<A,​F<A,​A>> f)
      Folds this digit to the right using the given function.
      A reduceRight​(F<A,​F<A,​A>> f)
      Folds this digit to the right using the given function.
      (package private) abstract P3<Option<Digit<V,​A>>,​A,​Option<Digit<V,​A>>> split1​(F<V,​java.lang.Boolean> predicate, V acc)  
      (package private) Option<Digit<V,​A>> tail()  
      abstract Stream<A> toStream()  
      java.lang.String toString()  
      FingerTree<V,​A> toTree()
      Returns the tree representation of this digit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • foldRight

        public abstract <B> B foldRight​(F<A,​F<B,​B>> f,
                                        B z)
        Folds this digit to the right using the given function and the given initial value.
        Parameters:
        f - A function with which to fold this digit.
        z - An initial value to apply at the rightmost end of the fold.
        Returns:
        The right reduction of this digit with the given function and the given initial value.
      • foldLeft

        public abstract <B> B foldLeft​(F<B,​F<A,​B>> f,
                                       B z)
        Folds this digit to the left using the given function and the given initial value.
        Parameters:
        f - A function with which to fold this digit.
        z - An initial value to apply at the leftmost end of the fold.
        Returns:
        The left reduction of this digit with the given function and the given initial value.
      • reduceRight

        public final A reduceRight​(F<A,​F<A,​A>> f)
        Folds this digit to the right using the given function.
        Parameters:
        f - A function with which to fold this digit.
        Returns:
        The right reduction of this digit with the given function.
      • reduceLeft

        public final A reduceLeft​(F<A,​F<A,​A>> f)
        Folds this digit to the right using the given function.
        Parameters:
        f - A function with which to fold this digit.
        Returns:
        The right reduction of this digit with the given function.
      • map

        public final <B> Digit<V,​B> map​(F<A,​B> f,
                                              Measured<V,​B> m)
        Maps a function across the elements of this digit, measuring with the given measurement.
        Parameters:
        f - A function to map across the elements of this digit.
        m - A measuring for the function's domain (destination type).
        Returns:
        A new digit with the same structure as this digit, but with all elements transformed with the given function and measured with the given measuring.
      • match

        public abstract <B> B match​(F<One<V,​A>,​B> one,
                                    F<Two<V,​A>,​B> two,
                                    F<Three<V,​A>,​B> three,
                                    F<Four<V,​A>,​B> four)
        Structural pattern matching on digits. Applies the function that matches the structure of this digit.
        Parameters:
        one - A function to apply to this digit if it's One.
        two - A function to apply to this digit if it's Two.
        three - A function to apply to this digit if it's Three.
        four - A function to apply to this digit if it's Four.
        Returns:
        The result of applying the function matching this Digit.
      • measure

        public final V measure()
        Returns the sum of the measurements of this digit according to the monoid.
        Returns:
        the sum of the measurements of this digit according to the monoid.
      • toTree

        public final FingerTree<V,​A> toTree()
        Returns the tree representation of this digit.
        Returns:
        the tree representation of this digit.
      • lookup

        public abstract P2<java.lang.Integer,​A> lookup​(F<V,​java.lang.Integer> o,
                                                             int i)
      • length

        public abstract int length()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStream

        public abstract Stream<A> toStream()