These are chat archives for ramda/ramda

5th
Jul 2017
Luis Felipe López G.
@luishendrix92
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
@lucasschejtman
Jul 05 2017 02:14
@luishendrix92 I think what you're looking for average is http://ramdajs.com/docs/#mean
Lucas Schejtman
@lucasschejtman
Jul 05 2017 02:30
your directedByNolan could be simplified with a propEq
Philipp Wille
@Yord
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)
alpox
@alpox
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
@kurtmilam
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
@kurtmilam
Jul 05 2017 16:37
Seems to work? Maybe I'm overlooking something, though.
Kurt Milam
@kurtmilam
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.
alpox
@alpox
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
@kurtmilam
Jul 05 2017 17:35
:thumbsup: