These are chat archives for ramda/ramda

7th
Dec 2017
Adam Szaraniec
@mimol91
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' ( https://goo.gl/YJ1Ay4)
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
@jakubrpawlowski
Dec 07 2017 07:42
I think that you never watched that reduce video by mpj I linked for you :p
Adam Szaraniec
@mimol91
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
@mimol91
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
@jakubrpawlowski
Dec 07 2017 07:57
@mimol91 There is Eric Elliott's Medium series of (last time I checked) 13 articles starting with this one: https://medium.com/javascript-scene/composing-software-an-introduction-27b72500d6ea
@mimol91 Here is book by Kyle Simpson you can read too: https://github.com/getify/Functional-Light-JS
@mimol91 Here is another YouTube channel I learned a lot from: https://www.youtube.com/user/jesterxl
Syaiful Bahri
@syaiful6
Dec 07 2017 08:02
@mimol91 that's good, except it's not composable. but it fine.
i would recommend to read https://fsharpforfunandprofit.com/site-contents/, it site talk about F# in general, but it's good to build thinking functional.
and they also have series about fold and recursive: https://fsharpforfunandprofit.com/series/recursive-types-and-folds.html
Adam Szaraniec
@mimol91
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
@rickmed
Dec 07 2017 14:56
@syaiful6 what do you mean by it's not composable?
Brad Compton (he/him)
@Bradcomp
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
@mfidemraizer
Dec 07 2017 16:16
@alavkx oops! I see
Alec
@alavkx
Dec 07 2017 16:35
:)
@mimol91 a fix https://goo.gl/xs2EUd
@Bradcomp that bug is tricky..for some reason my brain tells me accumulator here should be scoped here
Brad Compton (he/him)
@Bradcomp
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:
Alec
@alavkx
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)
@Bradcomp
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.
Alec
@alavkx
Dec 07 2017 17:20
yet another landmine