Ramda 中 Haskell 的 const 函数的等价物
Equivalent of Haskell's const function in Ramda
Ramda 是否具有与 Haskell's const
function 相同的功能,即接受两个参数和 returns 第一个参数?
我知道它可以很容易地实现为 R.curry((a, b) => a)
,但如果 Ramda 已经有这样的功能,我想我应该使用它而不是我自己的实现。
这个函数在 Ramda 中被命名为 always
。
Returns a function that always returns the given value. Note that for non-primitives the value returned is a reference to the original value.
This function is known as const
, constant
, or K
(for K combinator) in other languages and libraries.
Ramda 不提供 a -> b -> a
类型的函数。正如 Gothdo 的回答所述,Ramda 确实提供了类似的 R.always :: a -> (() -> a)
。
在 ramda/ramda#1680 中提议向 Ramda 添加 a -> b -> a
函数,但该线程已经有一段时间没有活动了。
避难所确实提供了真正的const
功能,S.K :: a -> b -> a
。
Ramda 是否具有与 Haskell's const
function 相同的功能,即接受两个参数和 returns 第一个参数?
我知道它可以很容易地实现为 R.curry((a, b) => a)
,但如果 Ramda 已经有这样的功能,我想我应该使用它而不是我自己的实现。
这个函数在 Ramda 中被命名为 always
。
Returns a function that always returns the given value. Note that for non-primitives the value returned is a reference to the original value.
This function is known as
const
,constant
, orK
(for K combinator) in other languages and libraries.
Ramda 不提供 a -> b -> a
类型的函数。正如 Gothdo 的回答所述,Ramda 确实提供了类似的 R.always :: a -> (() -> a)
。
在 ramda/ramda#1680 中提议向 Ramda 添加 a -> b -> a
函数,但该线程已经有一段时间没有活动了。
避难所确实提供了真正的const
功能,S.K :: a -> b -> a
。