These are chat archives for ramda/ramda

Jul 2017
Luis Felipe López G.
Jul 05 2017 01:28

is there a better way for this?

const average = converge(divide, [sum, length])
const directedByNolan = compose(equals('Christopher Nolan'), prop('Director'))
const imdbRating = compose(Number, prop('imdbRating'))
const averageNolanRating = compose(average, map(imdbRating), filter(directedByNolan))

I'm surprised Ramda doesn't have an average function but apart from that, can I improve these point-free functions?

does R.sum work with strings?
Lucas Schejtman
Jul 05 2017 02:14
@luishendrix92 I think what you're looking for average is
Lucas Schejtman
Jul 05 2017 02:30
your directedByNolan could be simplified with a propEq
Philipp Wille
Jul 05 2017 14:44
Can one memoize lenses (and does this even make sense)?
(to be more thorough, can one memoize view and does this even make sense)
Jul 05 2017 15:23
@Yord I don't believe that it would make sense. If you would memoize it, it would response with the same data again to the same input - which only works for if you deal with pure function - no state involved.
lenses and a view on a lense are there to provide easy access to deeper state.
Therefore, if you would memoize a view, it would deliver fake data
Kurt Milam
Jul 05 2017 16:26
@alpox I don't believe a memoized lens would deliver fake data. The lens would be memoized based on the input object. You would expect it to return the same response for the same input.
@Yord As with most questions, the answer is probably 'it depends'. If you're viewing a lens on the same input object a million times in quick succession, the input object is reasonably small and you rarely need to use the same lens on input that varies, it might make sense.
Kurt Milam
Jul 05 2017 16:37
Seems to work? Maybe I'm overlooking something, though.
Kurt Milam
Jul 05 2017 16:45
@alpox To be fair, you would need to memoize view( myLens) / set( myLens) separately, and not memoize the lens, itself.
Jul 05 2017 17:18
@kurtmilam Right, it seems that memoize works differently than i thought.
The behavior i expected from memoize was the behavior of memoizeWith(identity, <someFunc>)
But it seems that memoize is just memoizeWith(toString, <someFunc>)
Kurt Milam
Jul 05 2017 17:35