These are chat archives for ramda/ramda

3rd
Sep 2015
Scott Sauyet
@CrossEye
Sep 03 2015 01:45
@101100: If you're doing this as a learning experience, it's an interesting exercise. But I would not make a fetish out of points-free. I think the following version is much more readable. (Of course the es6 syntax helps.):
``((a, b) => R.chain(id => R.filter(R.propEq('id', id), b), a))``
hemanth.hm
@hemanth
Sep 03 2015 07:04
under what license is web ramda-repl ?
Aldwin Vlasblom
@Avaq
Sep 03 2015 10:07

@CrossEye Agreed, I do believe this was meant to be an exercise though. :)

And coming back to it, @101100, I've found another way around the `(null)`-hack, much closer to my original plan. My first try was `R.converge(R.compose, R.flip(R.contains), R.always(R.prop('id')))`, but that returned a 2-ary function and I didn't understand why (it should only take in `a`). So I looked at the `converge` source today and noticed it chooses its arity based on the highest arity from the input functions, which was `2` for `R.flip(R.contains)`. So the fix was to flag it as `unary`, so the complete thing becomes:

``R.useWith(R.filter, R.converge(R.compose, R.unary(R.flip(R.contains)), R.always(R.prop('id'))), R.identity);``

I'm not saying it's a better solution by any means (there's still a secret noop), but I did learn something new about `converge` I wanted to share. :)

Raine Virta
@raine
Sep 03 2015 12:40
how do you map over a return value of a function that returns a thenable in `pipe`? is there a ramda function that checks for `.then`?
it used to be possible to use `pipeP` so that not all functions returned a Promise
Raine Virta
@raine
Sep 03 2015 12:52
ramda/ramda#1314
Raine Virta
@raine
Sep 03 2015 13:04
``````const then = curry((fn, thenable) => thenable.then(fn));
const getStuff = pipe(formatPath, readFile, then(toUpper));``````
there's probably a better way than coming up with a `map` (the `then`) specific to promises
Danielle McLean
@00dani
Sep 03 2015 13:39
Well, typewise `R.chain` should be the right function for "mapping" promises. Of course, the standard promise API is incompatible with fantasy-land's monad definitions so it doesn't quite work out.
Martin Algesten
@algesten
Sep 03 2015 17:37

I was trying to parse xml data using cheerio/jQuery the other day and it struck me how awkward those libraries are for functional programming.

So I decided to learn top down operator precedence-parsers and applied it to parsing CSS-expressions. End result is an attempt to make a lightweight tool for reading XML/HTML in a functional style. https://github.com/algesten/zu

Now I want it to work really well with Ramda, but I'm a bit stuck on currying. I want to have `zu.parents(nodes, 'div > span')` be curried as `zu.parents('div > span')(nodes)` but maybe also `zu.parents(nodes)('div > span')` but then that last form is not possible since i may also want `zu.parents(nodes)`as a one-arg version (just parents without an expression).

Does any of you fine minds have any thoughts on that currying conundrum?

jeffcato
@jeffcato
Sep 03 2015 18:27
does ramda have an abstraction for switch or if/else that would make sense to use here?:
``````switch(req.method) {
case 'GET':
getCacheKey(cache, url).fork(
function(err) {
getDocuments(getCollection(db, collectionName)).fork(
send404(res),
sendPage(res, cache, collectionName, url)
);
},
function(value) {
console.log('sent cached value');
res.end(value);
}
);
break;
case 'POST':
// handle post req's
break;
default:
send404(res, null);
break;
}``````
Scott Sauyet
@CrossEye
Sep 03 2015 18:27
@algesten: raganwald does this by offering a second version of many functions, suffixed with 'With'. So `parents(selector)(nodes)` and `parentsWith(nodes)(selector)` or vice versa.
jeffcato
@jeffcato
Sep 03 2015 18:28
or possibly a monad in ramda-fantasy could handle it better?
i'm pretty new to functional programming in general so forgive me if this is obvious
Scott Sauyet
@CrossEye
Sep 03 2015 18:33
@jeffcato: Ramda does have both `ifElse` and `cond`. One of those might help.
Martin Algesten
@algesten
Sep 03 2015 18:37
@CrossEye thanks! i check raganwald out
Scott Sauyet
@CrossEye
Sep 03 2015 18:42
@algesten, the first edition of his book JavaScript Allongé was a huge inspiration for me.
Almost finished with the second.
jeffcato
@jeffcato
Sep 03 2015 18:52
@CrossEye ok thanks - i'll give one of those a shot
Martin Algesten
@algesten
Sep 03 2015 19:03
@CrossEye googling. thanks :D
i just realised i had a bunch of essays to go through on his site.
good times!
Raine Virta
@raine
Sep 03 2015 20:37
`@typedef` annotation in the lens functions throws off jsdoc parser, making it think those functions' `kind` is `typedef` (while it should be `function`), the name property is wrong as well
that's why they are not picked up by ramda-json-docs
Scott Sauyet
@CrossEye
Sep 03 2015 21:22
I hacked together something to avoid that on the last release. I was hoping someone who understood lenses better could update the docs before the next one. ping @davidchambers.
David Chambers
@davidchambers
Sep 03 2015 22:10
@algesten, I look forward to trying zu! I’d been thinking of writing a similar library myself. Hopefully that’s no longer necessary.
Scott Sauyet
@CrossEye
Sep 03 2015 22:21
Glad you said something @davidchambers! I meant to look at this tonight, but it had already fallen off my radar. Too many things to do! Now I can add one more that I'm really interested in. Where to find the time?...
Scott Sauyet
@CrossEye
Sep 03 2015 22:49
@algesten: just looked at the zu API. Very nice!