无点动态功能组合 [英] Pointfree dynamic function composition
问题描述
我正试图将此功能重构为无点的.
I'm trying to refactor this function to be pointfree.
function siblings(me) {
return R.pipe(family, R.reject(equalsMe(me)))(me);
}
我想将 me
和 family
返回的值一起传递给函数.
I'd like to pass me
to a function down the pipe along with the value that family
returns.
使用 R.useWith
或 R.converge
和 R.identity
或 R .__
(甚至不确定我是否应该使用该功能),但没有任何效果.
Tried a few things with R.useWith
or R.converge
with R.identity
or R.__
(not even sure if I should be using that) but found nothing to work.
推荐答案
如果我正确理解, family
是一个可以接受一个人并返回一个家庭成员(包括该人)列表的函数,例如
If I understand correctly family
is a function that takes a person and returns a list of family members (including that person) e.g.
family(2);
//=> [1, 2, 3]
然后您要创建一个函数 siblings
,该函数接受一个人并仅返回其兄弟姐妹,例如
Then you want to create a function siblings
which takes a person and returns only their siblings e.g.
siblings(2);
//=> [1, 3]
我个人认为,如果这样编写,您的函数会更好读:
Personally I think your function would read slightly better if it was written this way:
const siblings = me => reject(equals(me), family(me));
siblings(2);
//=> [1, 3]
如果您真的想要它的无点版本,则可以使用 converge
,但是我真的认为这没有什么更好的:
If you really wanted a pointfree version of it, you could use converge
but I really don't think it is any better:
const siblings = converge(reject, [unary(equals), family]);
这篇关于无点动态功能组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!