These are chat archives for ramda/ramda

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

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

Jul 22 2016 04:29 UTC
@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 UTC
_Just { value: _Just { value: 2 } }
James Forbes
@JAForbes
Jul 22 2016 04:33 UTC
@Bradcomp oh right, that is pretty cool, I suppose you could do lift(lift(add))(a,a) as well
Jul 22 2016 04:35 UTC
You can!
James Forbes
@JAForbes
Jul 22 2016 04:35 UTC
@ram-bot
const a = Maybe.Just(Maybe.Just(1))

lift(lift(add))(a, a)
ram-bot
@ram-bot
Jul 22 2016 04:35 UTC
_Just { value: _Just { value: 2 } }
Jul 22 2016 04:36 UTC
It works with different monads too (of course) http://goo.gl/Ut3HHW
James Forbes
@JAForbes
Jul 22 2016 04:36 UTC
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)
Jul 22 2016 04:37 UTC
Yeah, like a liftNLevels type of thing
James Forbes
@JAForbes
Jul 22 2016 04:37 UTC
yeah exactly
Tushar Mathur
@tusharmath
Jul 22 2016 08:13 UTC
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 UTC
@tusharmath R.reduce(func, [], R.range(0, 10))
provided func returns the collection
Tushar Mathur
@tusharmath
Jul 22 2016 09:13 UTC
@vsviridov wouldn't R.range be slower approach considering it would create an unnecessary array?
Vasili Sviridov
@vsviridov
Jul 22 2016 09:13 UTC
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 UTC
You might also be interested in R.unfold
Vasili Sviridov
@vsviridov
Jul 22 2016 09:16 UTC
@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 UTC
habit of using let and const :)
@vsviridov So it wont be as fast as a loop
?
Vasili Sviridov
@vsviridov
Jul 22 2016 09:18 UTC
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 UTC
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 UTC
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.
Tushar Mathur
@tusharmath
Jul 22 2016 09:31 UTC
Vasili Sviridov
@vsviridov
Jul 22 2016 09:32 UTC
@tusharmath neat... good to know
Tushar Mathur
@tusharmath
Jul 22 2016 09:32 UTC
Thanks!