fj.data.fingertrees.Four Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
package fj.data.fingertrees;
import fj.P;
import fj.P2;
import fj.P3;
import fj.Show;
import fj.data.Option;
import fj.data.Stream;
import fj.data.vector.V4;
import fj.F;
import static fj.data.Option.none;
import static fj.data.Option.some;
import static fj.data.fingertrees.FingerTree.mkTree;
/**
* A four-element prefix or suffix of a finger tree.
*/
public final class Four extends Digit {
private final V4 as;
Four(final Measured m, final V4 as) {
super(m);
this.as = as;
}
public B foldRight(final F> aff, final B z) {
return aff.f(as._1()).f(aff.f(as._2()).f(aff.f(as._3()).f(aff.f(as._4()).f(z))));
}
public B foldLeft(final F> bff, final B z) {
return as.toStream().foldLeft(bff, z);
}
@Override public B match(
final F, B> one, final F, B> two, final F, B> three,
final F, B> four) {
return four.f(this);
}
/**
* Returns the elements of this digit as a vector.
*
* @return the elements of this digit as a vector.
*/
public V4 values() {
return as;
}
@Override P3