[英]Ramda ifElse is not executed for function with multiple arguments
Can somebody explain me this behavior, or is it a bug? 有人可以向我解释这种行为,还是一种错误?
const firstTest = (a) => console.log(a, 'this will be executed');
const secTest = (a, b) => console.log(a, 'this will not be executed');
const firstIfElse = R.ifElse(R.T, firstTest, () => null);
const unexpectedIfElse = R.ifElse(R.T, secTest, () => null);
firstIfElse('logging appears as expected');
unexpectedIfElse('no logging');
Your second function is a curried binary function. 您的第二个功能是咖喱的二进制功能。
ifElse
chooses the maximum arity of the three functions passed to it, predicate
, ifTrue
, and ifFalse
. ifElse
在传递给它的三个函数predicate
, ifTrue
和ifFalse
选择最大ifFalse
。 RT
has arity 1, as does () => null
, but secTest
has arity 2, so unexpectedIfElse
also has arity 2. RT
具有1的secTest
, () => null
也是如此,但是secTest
具有2的secTest
,因此unexpectedIfElse
secTest
也具有2的secTest
。
When you call unexpectedIfElse
with 'no logging', you get back a function waiting for the (useless) b
parameter. 当您以“不记录”调用
unexpectedIfElse
时,您将获得一个等待(无用) b
参数的函数。
There are reasons not to like this additional complexity, but there are times when it's very useful, especially for the predicate. 有理由不喜欢这种额外的复杂性,但是有时候它非常有用,尤其是对于谓词。
You can fix your issue by calling it like 您可以通过以下方式解决问题:
unexpectedIfElse('no logging', 'ignored');
or like 或喜欢
unexpectedIfElse('no logging')('ignored')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.