fj.data.fingertrees.Node 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.F;
import fj.P;
import fj.P2;
import fj.P3;
import fj.data.Option;
import fj.data.Stream;
import static fj.Function.curry;
/**
* An inner node of the 2-3 tree.
*/
public abstract class Node {
private final Measured m;
private final V measure;
public abstract B foldRight(final F> f, final B z);
public abstract B foldLeft(final F> f, final B z);
public static F, B>> foldLeft_(final F> bff) {
return curry((b, node) -> node.foldLeft(bff, b));
}
public static F, B>> foldRight_(final F> aff) {
return curry((b, node) -> node.foldRight(aff, b));
}
public final Node map(final F f, final Measured m) {
return match(
node2 -> new Node2<>(m, node2.toVector().map(f)),
node3 -> new Node3<>(m, node3.toVector().map(f))
);
}
public static F, Node> liftM(final F f, final Measured m) {
return node -> node.map(f, m);
}
public abstract Digit toDigit();
Node(final Measured m, final V measure) {
this.m = m;
this.measure = measure;
}
public final V measure() {
return measure;
}
final Measured measured() {
return m;
}
abstract P3