These are chat archives for ramda/ramda

3rd
Dec 2014
Jethro Larson
@jethrolarson
Dec 03 2014 19:48
I stumbled upon R.lens and was googling around for the benefits of using them. I'm not quite grokking it yet, you know of a good explanation for someone that primarily writes JS?
David Chambers
@davidchambers
Dec 03 2014 19:49
I haven't grokked lenses myself yet, so I'm interested in reading about them too!
Jethro Larson
@jethrolarson
Dec 03 2014 19:50
The videos I've found so far are in haskell or scala and these topics are tricky enough without getting having to translate syntax
David Chambers
@davidchambers
Dec 03 2014 19:51
I hear ya.
Raine Virta
@raine
Dec 03 2014 19:56
hey guys, got a question
var findCall    = R.compose(R.find, R.where, R.createMapEntry('call'));
var findUserArg = R.compose(R.head, R.prop('args'), findCall('user'));
this is what I have so far, findCall('user')([{ call: 'user', args: [1] }]) returns that first object in the array
problem is that I get an error from R.prop('args') if findCall doesn't find any object
how could I avoid running rest of the steps in compose if the findCall produces nothing
David Chambers
@davidchambers
Dec 03 2014 20:00
Mind editing your comment to put the code in a code block? It's a bit hard to read as is.
Raine Virta
@raine
Dec 03 2014 20:02
sure, kind of new to gitter
Jethro Larson
@jethrolarson
Dec 03 2014 20:05
Not a solution but I noticed this is shorter:
var findCall = R.compose(R.find, R.propEq('call'));
David Chambers
@davidchambers
Dec 03 2014 20:07
One approach is to wrap the result of applying R.find in an array, filtering, then using R.map(f) in place of f.
R.pipe(findCall,
       R.of,
       R.reject(R.eq(undefined)),
       R.map(R.pipe(R.prop('args'),
                    R.head)))
What you really want here is the Maybe monad.
Jethro Larson
@jethrolarson
Dec 03 2014 20:34
So something like?
Maybe(findCall).chain(R.compose(R.head, R.prop('args'));
David Chambers
@davidchambers
Dec 03 2014 20:58
Something like that, yes. I haven't actually used the Maybe extension yet.
Raine Virta
@raine
Dec 03 2014 20:58
oh ramda includes Maybe
i've used data.maybe from npm before
Jethro Larson
@jethrolarson
Dec 03 2014 21:00
Maybe is in the ext/types folder in the repo but it's not in the main ramda.js
BTW so far this is the best explanation I've found on lenses, but he still leaves me behind http://vimeo.com/104807358
Would probably be clearer if he didn't sugar makeLenses
Raine Virta
@raine
Dec 03 2014 21:04
are the Reader and IO monads actually useful in javascript?
Jethro Larson
@jethrolarson
Dec 03 2014 21:05
If you're trying to stay pure, I'd imagine so, but I've not used them much yet
Raine Virta
@raine
Dec 03 2014 21:43
what does the chain function (in Maybe and others) correspond to in haskell?
Scott Sauyet
@CrossEye
Dec 03 2014 23:59