These are chat archives for ramda/ramda

3rd
Apr 2019
Alex Panchuk
@alexpanchuk
Apr 03 06:12
Hi. What function should i use to get something like this:
const someFunc = (fn1, fn2, data) => fn1(data) === fn2(data)
Riku Tiira
@rikutiira
Apr 03 06:50
Nothing wrong with that but you can do that with R.converge(R.equals, [fn1, fn2])
Alex Panchuk
@alexpanchuk
Apr 03 09:01
@rikutiira thank you
Fabien Bourgeois
@Yakulu
Apr 03 16:47
Hello. Is there a way to achieve lazy evaluation with ramda (like I want the 3 first objects matching a condition inside an array and do not want to evaluate the whole array) ? If yes, can someone share a sample ?
Bijoy Thomas
@bijoythomas
Apr 03 16:50
@Yakulu will something like this help? https://ramdajs.com/docs/#reduced
@Yakulu
let arr = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6]

reduce((acc, elem) => {
  if (elem < 9) {
    acc.push(elem)
  }
  return acc.length === 3 ? reduced(acc): acc
}, [], arr) // => [1, 2, 3]
Fabien Bourgeois
@Yakulu
Apr 03 16:58
@bijoythomas Perfect, thanks
Brad Compton (he/him)
@Bradcomp
Apr 03 17:00

The canonical Ramda way to do lazy evaluation is transducers.

into([], compose(filter(lt(__, 10)), take(3)))(arr) // [1,2,3]

Check out transduce and into, but it's a bigger subject than a simple example

For instance, note how compose is 'backwards' from what it would be if you were composing 'normal' functions
Fabien Bourgeois
@Yakulu
Apr 03 17:01
Yes, it's on my TODO, and I think too it's way larger subject :)
Brad Compton (he/him)
@Bradcomp
Apr 03 17:01
:+1:
Fabien Bourgeois
@Yakulu
Apr 03 17:05
Thanks again !
Mike Lambert
@lambert-velir
Apr 03 18:54
Are the docs for R.adjust wrong?
oh, I think I'm using an old version
it appears the arguments were swapped