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.F2;
import fj.P2;
import fj.P3;
import fj.data.Option;
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(new F2, B>() {
public B f(final B b, final Node node) { return node.foldLeft(bff, b); }
});
}
public static F, B>> foldRight_(final F> aff) {
return curry(new F2, B>() {
public B f(final B b, final Node node) { return node.foldRight(aff, b); }
});
}
public final Node map(final F f, final Measured m) {
return match(new F, Node>() {
public Node f(final Node2 node2) {
return new Node2(m, node2.toVector().map(f));
}
}, new F, Node>() {
public Node f(final Node3 node3) {
return new Node3(m, node3.toVector().map(f));
}
});
}
public static F, Node> liftM(final F f, final Measured m) {
return new F, Node>() {
public Node f(final Node node) {
return 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;
}
Measured measured() {
return m;
}
abstract P3