Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

ramda.js - Ramda: Parameters in nested loops

I am trying to rewrite Javascript code point-free with Ramda. This is as far as I got:

R.reject((something: Something) =>
  R.any(
    R.allPass([R.eqProps('property1', something),
               R.propEq('property2', otherObject)]),
    list1),
  list2 ?? [])

My next step is to get rid of the something variable (before I take care of other variables). How can I achieve that?

Here is the original code:

list2?.filter((something: Something) =>
  list1.every(item =>
    (item.property1 !== something.property1) || (item.property2 !== otherObject))
  )
)
question from:https://stackoverflow.com/questions/65922471/ramda-parameters-in-nested-loops

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a best-effort (in the absence of runnable code) at making your inner lambda pointfree.

list2?.filter((something: Something) =>
  R.all(
    R.pipe(
      R.repeat(1),
      R.ap([prop('property1'), R.prop('property2')]),
      R.zipWith(R.flip(R.applyTo), R.map(R.equals, [something.property1, otherObject])),
      R.reduce(R.and, true),
      R.not
    ),
    list1
  )
)

I really wouldn't bother trying to make the outer lambda pointfree (I just don't think it'll be readable)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...