1

假设您有以下代码:

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);

addOnefunc1or结合func2比较容易:

const res = R.compose(
  S.map(addOne),
  func1
)(); 

但是如何add使用func1andfunc2作为参数调用呢?

ps 我知道 ramda 提供了一个add功能。将该示例视为对现实世界问题的抽象。

4

1 回答 1

4

您可能正在寻找以下lift2功能

const addEithers = S.lift2(add)

console.log(addEithers(func1())(func2()))

或者,您可以使用ap

S.ap(S.map(add)(func1()))(func2())
于 2020-03-21T21:30:08.430 回答