突破,
诀窍是您需要取消 arity 函数并将其绑定到您的选项的乘积。
所以在例子中:
arity-5 实现
import fj.F;
import fj.F5;
import fj.P5;
public abstract class F5Optional<At, Bt, Ct, Dt, Et, Ft> extends F5<At, Bt, Ct, Dt, Et, Ft> {
public final F<P5<At, Bt, Ct, Dt, Et>, Ft> tupleize() {
return new F<P5<At, Bt, Ct, Dt, Et>, Ft>() {
@Override
public Ft f(final P5<At, Bt, Ct, Dt, Et> p) {
return F5Optional.this.f(p._1(), p._2(), p._3(), p._4(), p._5());
}
};
}
}
用法:
F5Optional<Integer, Integer, Integer, Integer, Integer, Option<Integer>> f5 = new F5Optional<Integer, Integer, Integer, Integer, Integer, Option<Integer>>() {
@Override
public Option<Integer> f(Integer a, Integer b, Integer c, Integer d, Integer e) {
return Option.some(a + b + c + d + e);
}
};
Option<Integer> test2 = b.bindProduct(Option.some(1), Option.some(1), Option.some(1), Option.some(1)).bind(f5.tupleize());
Assert.assertTrue(new Integer(8).equals(test2.toNull()));
Option<Integer> nullInteger = Option.none();
Option<Integer> test3 = b.bindProduct(nullInteger, Option.some(1), Option.some(1), Option.some(1)).bind(f5.tupleize());
Assert.assertTrue(test3.isNone());