两个都操作

问题描述 投票:0回答: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);

addOnefunc1func2的组合相对容易:

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

但是如何使用addfunc1作为参数来调用func2

ps.s。我知道ramda提供了add功能。将示例视为现实问题的抽象。

javascript functional-programming ramda.js sanctuary fantasyland
1个回答
0
投票

您可能正在寻找lift2 function

lift2

或者,您可以使用const addEithers = S.lift2(add) console.log(addEithers(func1())(func2()))

ap
© www.soinside.com 2019 - 2024. All rights reserved.