假设您具有以下代码:
import R from "ramda";
import S from "sanctuary";
import { Left, Right } from "sanctuary-either";
const add = R.curry((p1, p2) => p1 + p2);
const addOne = add(1);
const func1 = () => Right(2);
const func2 = () => Right(7);
addOne
与func1
或func2
的组合相对容易:
const res = R.compose(
S.map(addOne),
func1
)();
但是如何使用add
和func1
作为参数来调用func2
?
ps.s。我知道ramda提供了add
功能。将示例视为现实问题的抽象。
您可能正在寻找lift2
function:
lift2
或者,您可以使用const addEithers = S.lift2(add)
console.log(addEithers(func1())(func2()))
:
ap