[英]Equivalent of Haskell's const function in Ramda
Does Ramda have a function that works the same as Haskell's const
function , ie takes two parameters and returns the first one? Ramda是否具有与Haskell的
const
函数相同的功能 ,即采用两个参数并返回第一个参数?
I'm aware that it could be easily implemented as R.curry((a, b) => a)
, but if Ramda already has such a function, I think I should use it instead of my own implementation. 我知道可以很容易地将其实现为
R.curry((a, b) => a)
,但是如果Ramda已经具有这样的功能,我想我应该使用它而不是自己的实现。
This function is named always
in 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.在其他语言和库中,此函数称为
const
,constant
或K
(对于K组合器)。
Ramda doesn't provide a function of type a -> b -> a
. Ramda不提供类型
a -> b -> a
a- a -> b -> a
的函数。 As Gothdo's answer states, Ramda does provide R.always :: a -> (() -> a)
which is similar. 正如Gothdo的回答所指出的那样,
R.always :: a -> (() -> a)
确实提供了R.always :: a -> (() -> a)
。
Adding an a -> b -> a
function to Ramda was proposed in ramda/ramda#1680 , but that thread has not been active for some time. 在ramda / ramda#1680中建议向Ramda添加a-
a -> b -> a
函数,但是该线程已经有一段时间没有被激活了。
Sanctuary does provide a true const
function, SK :: a -> b -> a
. Sanctuary确实提供了真正的
const
函数,即SK :: a -> b -> a
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.