fj.data.fingertrees.Node3 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.P3;
import fj.data.Option;
import fj.data.vector.V3;
import fj.F;
import fj.P2;
import static fj.data.Option.none;
import static fj.data.Option.some;
import static fj.data.fingertrees.FingerTree.mkTree;
/**
* A three-element inner tree node.
*/
public final class Node3 extends Node {
private final V3 as;
Node3(final Measured m, final V3 as) {
super(m, m.sum(m.measure(as._1()), m.sum(m.measure(as._2()), m.measure(as._3()))));
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(z)));
}
public B foldLeft(final F> bff, final B z) {
return bff.f(bff.f(bff.f(z).f(as._1())).f(as._2())).f(as._3());
}
public B match(final F, B> n2, final F, B> n3) {
return n3.f(this);
}
public Digit toDigit() {
return new Three(measured(), as);
}
P3