These are chat archives for ramda/ramda

22nd
Jul 2016
James Forbes
@JAForbes
Jul 22 2016 04:06

Is there a nice approach for lifting n levels. E.g. if you have 2 streams that contain maybes. You'd have to lift twice.

R.lift(function(justA,justB){
  R.lift(function(a,b){
     // now I have the raw values a,b
  })(justA, justB)
})(streamA, streamB)

I'm sure I'm missing something obvious

Brad Compton (he/him)
@Bradcomp
Jul 22 2016 04:29
@JAForbes Dunno if it helps, but you can at least compose multiple lifts
@ram-bot
const a = Maybe.Just(Maybe.Just(1))

compose(lift, lift)(add)(a, a)
ram-bot
@ram-bot
Jul 22 2016 04:29
_Just { value: _Just { value: 2 } }
James Forbes
@JAForbes
Jul 22 2016 04:33
@Bradcomp oh right, that is pretty cool, I suppose you could do lift(lift(add))(a,a) as well
Brad Compton (he/him)
@Bradcomp
Jul 22 2016 04:35
You can!
James Forbes
@JAForbes
Jul 22 2016 04:35
@ram-bot
const a = Maybe.Just(Maybe.Just(1))

lift(lift(add))(a, a)
ram-bot
@ram-bot
Jul 22 2016 04:35
_Just { value: _Just { value: 2 } }
Brad Compton (he/him)
@Bradcomp
Jul 22 2016 04:36
It works with different monads too (of course) http://goo.gl/Ut3HHW
James Forbes
@JAForbes
Jul 22 2016 04:36
still it'd be nice to have a kind of liftN (even though liftN exists for multiple arities, but you know what I mean hopefully)
Brad Compton (he/him)
@Bradcomp
Jul 22 2016 04:37
Yeah, like a liftNLevels type of thing
James Forbes
@JAForbes
Jul 22 2016 04:37
yeah exactly
Tushar Mathur
@tusharmath
Jul 22 2016 08:13
let i = 10
let out  = []
 while (i-- > 0) {
    out = func(out)
  }
return out
can it be simplified ?
Vasili Sviridov
@vsviridov
Jul 22 2016 09:09
@tusharmath R.reduce(func, [], R.range(0, 10))
provided func returns the collection
Tushar Mathur
@tusharmath
Jul 22 2016 09:13
@vsviridov wouldn't R.range be slower approach considering it would create an unnecessary array?
Vasili Sviridov
@vsviridov
Jul 22 2016 09:13
You could also do Array(10) since Ramda doesn't skip over undefined keys
instead of Range(0,10)
Scott Christopher
@scott-christopher
Jul 22 2016 09:15
You might also be interested in R.unfold
Vasili Sviridov
@vsviridov
Jul 22 2016 09:16
@tusharmath, you can't really optimize it much from the loop, however you can get rid of free-floating variables, to make it more concise.
also, as an aside, why lets?
Tushar Mathur
@tusharmath
Jul 22 2016 09:17
habit of using let and const :)
@vsviridov So it wont be as fast as a loop
?
Vasili Sviridov
@vsviridov
Jul 22 2016 09:18
well, it might be as fast, it'll probably be same Big-O + some constant.
what exactly are you trying to optimize for?
I just feel weird, when people use let where there's not a lexical scope that makes it necessary, that's all...
Tushar Mathur
@tusharmath
Jul 22 2016 09:20
There was a scope, but I removed it for readability sake.
I just want to call a function recursively
Vasili Sviridov
@vsviridov
Jul 22 2016 09:21
recursion will always be slower, since tail call optimization is not supported yet, AFAIK, and that optimization unrolls it into a loop anyway.
I prefer reduce to avoid unnecessary variables, not to mention, Ramda's are all partially applied, so they can be reusable on their own.
Vasili Sviridov
@vsviridov
Jul 22 2016 09:32
@tusharmath neat... good to know
Tushar Mathur
@tusharmath
Jul 22 2016 09:32
Thanks!