Copyright 2008 - 2010 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.fingertrees
Class Digit<V,A>

java.lang.Object
  extended by 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.


Method Summary
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.
<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.
 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.
 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, toString, 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 <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 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 FingerTree<V,A> toTree()
Returns the tree representation of this digit.

Returns:
the tree representation of this digit.

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

This software is released under an open source BSD licence.