Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 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 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...