These are chat archives for ramda/ramda

8th
May 2015
Jethro Larson
@jethrolarson
May 08 2015 02:12
Cool book, I can't wait for the rest!
pistacchio
@pistacchio
May 08 2015 09:46
Hi, I don't want to bring up any libraryX vs libraryY, in the opensource world it doesn't make very much sense. The scope of ramda is quite clearly the one to provide "functional functions" and it is great, but since most people that like relying on utility-belt libraries use something older like lodash, it would make sense to help the switch by including in ramda some utility functions that are not purely for functional programming. for example, lodash has "random", "sample", "after", "debounce" and some string utilities that may be very useful, and for someone waiting to switch it is annoying to import only such functions or having to define them by themselves. including all that is included in competitor libraries, while maybe not "pure" is surely smart and a matter of "real politics"
Seb Insua
@sebinsua
May 08 2015 10:38
@JediMindtrick Definitely go ahead and modify ramda-debug if you have any ideas - I am happy to take PRs, too. :) It's a very early attempt at the idea, and a lot can be broken up into smaller pieces or written better. One thing I'm fairly interested in doing is decoupling the formatting/logging by making the library emit events containing the execution data/types - then others could use this data how they wished: perhaps it is possible to integrate with other tools.
Seb Insua
@sebinsua
May 08 2015 10:51
I almost always find functional code clearer and easier to understand. But I don't always write it because when I fail at it it's costly for me to fix. The data can get screwed up half-way through a functional pipeline and I have to backtrack to find out at what point I made the error. It's often because I have strung together 5 or more functions to do something and haven't understood the purpose or type signature of at least one of them. I wonder if there is a typescript for Ramda; or whether by emitting the data from my library I might be able to attach sinon spies from outside the code...
Scott Sauyet
@CrossEye
May 08 2015 11:01
Someone did do a Typescript metadata file at one point. I can't research it really on my mobile, but I will look when I get in front of a computer.
Scott Sauyet
@CrossEye
May 08 2015 11:17
@pistacchio: one thing that may not be obvious is that we aren't competing with those libraries. It starts from the fact that Ramda is designed for a different style of coding. But it is more than that. We simply are not trying to win any competition. This project was created to scratch an itch. We wanted to program in a certain manner that wasn't served by the existing libraries. It was a learning experience to see how far we could carry that model. The authors of some libraries see their job as one of promotion, popping up all over Twitter to mention their library whenever a so-called competitor is mentioned. The Ramda team won't play that game. Whatever success Ramda enjoys will a side-effect (oh no!) of its technical decisions. And those will be constrained by the style of coding we look to use.
Raine Virta
@raine
May 08 2015 12:05
I don't see why a single library should provide every "utility" function a JS programmer might ever need. lodash's scope seems to be just that and for some reason people have come to expect the same from ramda
npm (and browserify) makes var debounce = require('debounce') very easy
Seb Insua
@sebinsua
May 08 2015 12:53
Perhaps there should be a wiki page in which people can put APIs built for use with Ramda that diverge away from its purpose?
Raine Virta
@raine
May 08 2015 13:39
Is there a way to negate sortBy's comparator to get a reverse order? I composed sort, comparator, lt and useWith and it's not very pretty
Scott Sauyet
@CrossEye
May 08 2015 14:47
@raine I've thought about that a few times and never found an API that made me happy. I usually end up piping into reverse.
@raine: Ramda's scope is not quite as wide as lodash's scope, when it comes to functions supported
But it's in the same ballpark, which does explain to some extent people's desire to simply use Ramda as a lodash replacement. For many uses, you can. But there are significant differences that will always trip up the unwary.
Scott Sauyet
@CrossEye
May 08 2015 14:54
@sebinsua: I belive Ramda's wiki is publicly editable. Do feel free to start such a page.
Scott Sauyet
@CrossEye
May 08 2015 15:08
I did ask about the status of the Typescript implementation of heard about. #360.
Seb Insua
@sebinsua
May 08 2015 15:35
Is there a nice way using the Ramda library to traverse a deeply-nested object/array (of which I do not know the depth) and transform each non-array/object value into another value?
Hardy Jones
@joneshf
May 08 2015 17:32
Maybe there should be a different sortBy api?
The current one seems very specific
that said, I feel like there might be a way to do it with the current api if your data is bounded somehow, or uses a specific subset of characters
Scott Sauyet
@CrossEye
May 08 2015 17:47
@sebinsua: There's nothing built in. But how about something like
var transform = R.curry(function (fn, obj) {
  return R.cond(
    [R.isArrayLike, R.map(transform(fn))],
    [R.is(Object), R.mapObj(transform(fn))],
    [R.T, fn]
  )(obj);
});
http:// bit.ly/1GTOLve
Sorry, wrong link, and can't seem to edit it.
Scott Sauyet
@CrossEye
May 08 2015 17:52
http:// bit.ly/1GTNnsA
Scott Sauyet
@CrossEye
May 08 2015 18:03
@joneshf: actually, if the value you return from sortBy is numeric, I suppose you can just negate it. But for the more general case, all I could see for the API is to add a boolean ascending/descending flag. And boolean flags always seem like code smell.
The main use case is for things like
sortBy (prop('name'), people)
Hardy Jones
@joneshf
May 08 2015 18:11
I think the less specific way is to allow a function that takes two elements and determines the sort order. Basically let the user supplied function do these lines: https://github.com/ramda/ramda/blob/master/src/sortBy.js#L38-L40
and actually, loking at that, it seems like you can just give any value so long as it doesn't blow up on comparisons
Scott Sauyet
@CrossEye
May 08 2015 18:15
We havecomparator for that. It takes a binary predicate (first is less than second?) and returns a comparator suitable for passing into R.sort or Array.prototype.sort.
Hardy Jones
@joneshf
May 08 2015 18:15
so you'd have
sortBy : (a -> a -> Number) -> [a] -> [a]
oh, so there is
Scott Sauyet
@CrossEye
May 08 2015 18:17
Yes. That's the signature of sort, which is modeled after the native one.
Hardy Jones
@joneshf
May 08 2015 18:20
in that case...
@raine depending on what your comparison is, would R.gte or R.flip make things clearer?
Scott Sauyet
@CrossEye
May 08 2015 18:25
Well that won't help for sortBy, which is still unary. It's simply a quick way of generating sort keys.
Hardy Jones
@joneshf
May 08 2015 18:41
true