Class Digit<V,A>

java.lang.Object
fj.data.fingertrees.Digit<V,A>
Direct Known Subclasses:
Four, One, Three, Two

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

  • Constructor Details

  • Method Details

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

      final Measured<V,A> measured()
    • 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.
    • tail

      final Option<Digit<V,A>> tail()
    • init

      final Option<Digit<V,A>> init()
    • split1

      abstract P3<Option<Digit<V,A>>,A,Option<Digit<V,A>>> split1(F<V,Boolean> predicate, V acc)
    • lookup

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

      public abstract int length()
    • toString

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

      public abstract Stream<A> toStream()