These are chat archives for ramda/ramda

Dec 2017
Adam Szaraniec
Dec 07 2017 07:36

Yesterday I've asked about solution for min-max from array in one loop - FP way. @syaiful6 show me how it can be done 'full fp-way' (
I was thinking about it and I came out with

const data = [1,2,3,4,5];
R.reduce((acc, val) => {
  const [min,max] = acc;
  if (val < min) acc[0] = val;
  if (val > max) acc[1] = val

  return acc;
}, [Infinity, -Infinity])(data)

What do you think about it?

Jakub R Pawlowski
Dec 07 2017 07:42
I think that you never watched that reduce video by mpj I linked for you :p
Adam Szaraniec
Dec 07 2017 07:47
There were only 'basics' in this video
I think approach with reduce is simpler (but it does everything , what needs to be done)
I've watched more videos, I think this guy is not the best expert - he did some mistake on some of video. I pref videos from mr boolean
Adam Szaraniec
Dec 07 2017 07:52
@jakubrpawlowski if you got any other videos/blog which are related to FP, could you please send me them . Do you recommend anything else?
Jakub R Pawlowski
Dec 07 2017 07:57
@mimol91 There is Eric Elliott's Medium series of (last time I checked) 13 articles starting with this one:
@mimol91 Here is book by Kyle Simpson you can read too:
@mimol91 Here is another YouTube channel I learned a lot from:
Syaiful Bahri
Dec 07 2017 08:02
@mimol91 that's good, except it's not composable. but it fine.
i would recommend to read, it site talk about F# in general, but it's good to build thinking functional.
and they also have series about fold and recursive:
Adam Szaraniec
Dec 07 2017 08:15
Thanks, I think form this list i know only about Kyle Simpson.
Eric did video about lodash you are doing it wrong, but I didnt read his artices :(
Rick Medina
Dec 07 2017 14:56
@syaiful6 what do you mean by it's not composable?
Brad Compton (he/him)
Dec 07 2017 15:14
@mimol91 Your solution is OK, however it isn't reusable due to the mutation of the accumulator. I have seen this sort of thing lead to subtle bugs in the past. See here
Matías Fidemraizer
Dec 07 2017 16:16
@alavkx oops! I see
Dec 07 2017 16:35
@mimol91 a fix
@Bradcomp that bug is tricky..for some reason my brain tells me accumulator here should be scoped here
Brad Compton (he/him)
Dec 07 2017 16:52
@alavkx It's a pitfall of going overboard with point free in an eagerly evaluated and mutable language. Unfortunately it's easy to make and tough to see, even when you know the trick :expressionless:
Dec 07 2017 16:58
AH ok
this is only happening because of curried reduce reusing the same context?
interesting.. and just when I thought I understood lexical scoping
Brad Compton (he/him)
Dec 07 2017 17:04
haha, yeah. When you call reduce(f, acc) without the final parameter, it closes over the accumulator, essentially keeping a reference to the array that it will use whenever you call the function with the final parameter.
Dec 07 2017 17:20
yet another landmine