These are chat archives for ramda/ramda

11th
Feb 2015
Scott Sauyet
@CrossEye
Feb 11 2015 02:11
My take is that DevDocs is a great additional channel, but that the library should still have its own dedicated site. I might be convinced otherwise with a strong argument. Do you know of other tools that are only generating docs for that?
Scott Sauyet
@CrossEye
Feb 11 2015 02:22
@jlesquembre: Ramda has R.sortBy. So this could be written R.sortBy(R.prop(name), data). And if you want to use comparator you can do: data.sort(R.comparator(function(a, b) {return a[name] < b[name];})). That's what comparator is for.
Hardy Jones
@joneshf
Feb 11 2015 02:28
the function returns an array of length 2, is this checked somehow?
Scott Sauyet
@CrossEye
Feb 11 2015 02:29
checked how?
unfoldr is not one of our better efforts, I must say.
Hardy Jones
@joneshf
Feb 11 2015 02:29
I dunno, just asking :)
well, I think it's great it exists
for sure
what don't you like about it?
Scott Sauyet
@CrossEye
Feb 11 2015 02:31
Its API probably followed too closely from Haskell without thinking through what should be done in JS. And we didn't and don't know Haskell that well, so it was the blind leading the blind. It was early, and I wanted something like it. I heard of unfolds somewhere, looked up the Haskell API and copied it over.
Note the recent name change not yet reflected in the docs.
It's now simply "unfold".
Hardy Jones
@joneshf
Feb 11 2015 02:34
ah
so from the implementation it loks like a left unfold
is that right?
Scott Sauyet
@CrossEye
Feb 11 2015 02:35
could be
Hardy Jones
@joneshf
Feb 11 2015 02:36
heh :)
Scott Sauyet
@CrossEye
Feb 11 2015 02:36
I'm really not sure of the difference for unfold. I understand it for folds.
Hardy Jones
@joneshf
Feb 11 2015 02:36
it would build the array in the opposite way
[1,2,3] vs [3,2,1]
or maybe it is still unfoldr
right based i mean
I think so
Scott Sauyet
@CrossEye
Feb 11 2015 02:39
var fib = function(n) {
    var count = 0; 
    return function(pair) {
        if (count++ < n) {
            return [pair[0], [pair[1], pair[0] + pair[1]]];
        }
    };
};

R.unfold(fib(10), [0, 1]);

[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]);
Does that constitute a left or right unfold (or is it ambiguous?)
Hardy Jones
@joneshf
Feb 11 2015 02:41
right
Scott Sauyet
@CrossEye
Feb 11 2015 02:42
Well, then right is, um, right!
Hardy Jones
@joneshf
Feb 11 2015 02:42
so if ramda-fantasy gets more robust, would the interface for this change?
i.e. using a function that returns a Maybe
rather than a function returning a Boolean or an Array
Scott Sauyet
@CrossEye
Feb 11 2015 02:46
We don't intend to make the main library dependent on the fantasy extension. We're trying to keep to more idiomatic Javascript than that. Which means that nothing in the main library will ever depend on a Maybe.
A related discussion about the API for unfoldr: ramda/ramda#457
Hardy Jones
@joneshf
Feb 11 2015 02:47
hmm
Scott Sauyet
@CrossEye
Feb 11 2015 02:49
I think if we want to go that far, we're probably already getting pretty close to wanting something like PureScript. One of our committers doesn't agree, and he's started another library to fill in the gaps using a few of the algebraic types: https://github.com/plaid/sanctuary
Hardy Jones
@joneshf
Feb 11 2015 02:52
hmm
well, I'm not really here to rock the boat :)
i think i'm missing what step and newSeed do differently
Scott Sauyet
@CrossEye
Feb 11 2015 02:55
We don't mind some boat-rocking!
Where are you looking at step and newSeed?
Scott Sauyet
@CrossEye
Feb 11 2015 03:01
Well, that was just a discussion. But the idea was to stop working in pairs and having atomic functions for what we wanted to do. The current function has your callback return the equivalent of [step(seed), newSeed(seed)]. We never actually did anything with those ideas, but we might one day, as they feel a little closer to normal Javascript than the current API.
Hardy Jones
@joneshf
Feb 11 2015 04:01
makes sense
what about returning an object?
Scott Sauyet
@CrossEye
Feb 11 2015 04:16
Always possible of course. But that object would need a different shape (or should simply be undefined/null to stop the iteration, so, while it'd be a bit more idiomatic, it's not really clean.
Arnau Siches
@arnau
Feb 11 2015 04:40
hi, what is the intended way to iterate over an Object? So, an equivalent of R.forEach for Object?
Hardy Jones
@joneshf
Feb 11 2015 05:49
@davidchambers
Hardy Jones
@joneshf
Feb 11 2015 06:30
why do compose and pCompose both exist?
aren't these the same abstraction?
oh, I guess there's not even a fantasy thing for that
David Chambers
@davidchambers
Feb 11 2015 06:41
Thanks, @joneshf. I should add mfilter to Sanctuary.
Hardy Jones
@joneshf
Feb 11 2015 06:46
it'd be nice to have an idea of MonadPlus so you'd only have to write it once though
well, I mean really mfilter == filter just the more general version of it
Arnau Siches
@arnau
Feb 11 2015 06:53
@joneshf isn’t mapObj equivalent to map? If so, what is the difference between map and forEach? I’m a bit confused here sorry :S
Hardy Jones
@joneshf
Feb 11 2015 06:54
@arnau, or sorry, I misread your question
s/or/oh/
Arnau Siches
@arnau
Feb 11 2015 06:55
@joneshf ah np :)
José Luis Lafuente
@jlesquembre
Feb 11 2015 12:34

@CrossEye Thanks for the answer, but the reason to use my own sortBy is because I have an array of objects, and I want to order them using 2 properties. I mean, order by prop1 and if they are equal, order by prop2.

The complete code looks like this:

var sortBy = R.curry(function(name, a, b){
    if(a[name] < b[name]) return -1;
    else if(a[name] > b[name]) return 1;
    else return 0;
});
R.sort(R.or(sortBy('prop1') , sortBy('prop2'))) (data);

I'd like to know if there is a better solution for it, to avoid implement my own sortBy.

Scott Sauyet
@CrossEye
Feb 11 2015 14:16
@jlesquembre I feel as though there's probably some points-free way to do that, but I'm not seeing it. But there's nothing built-in to do that. If you had some string that would sort before all the possible character in your various properties, you could probably do it more simply with the built-in sortBy, just building up a single string with that as a separator.
Scott Sauyet
@CrossEye
Feb 11 2015 14:23
@arnau: What do you want to map over? The keys? The values? The key-value pairs? You can get a list to iterate over with keys(obj), values(obj), or toPairs(obj). If you want to include prototype properties you can use keysIn(obj), valuesIn(obj), or toPairsIn(obj). With any of these results you can then use forEach.
Hardy Jones
@joneshf
Feb 11 2015 16:06
@jlesquembre, well if you want to clean up sortBy you would want a function similar to on: http://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Function.html#v:on so in this case, you'd also want a compare like function as well to return the Number i guess it compares to?
@jlesquembre, so something like: var sortByProp = R.pipe(R.prop, R.on(R.comparator(R.lt)))
for some definition of on
but that's kind of weird
Danny Arnold
@despairblue
Feb 11 2015 16:56
@CrossEye I don't think any other tool is using devdocs as it's only documentation target. So yeah, it seems to be a good idea to keep ramdajs.com/docs. But still if people complain over the way it works one could point them to devdocs.io. Would be one less thing to worry about. Other projects that are on devdocs.io have only markdown pages as documentation (like d3), which is fine, since I can always go to devdocs.io/d3 if I want to look up a lot of functions in rapid succession.
David Chambers
@davidchambers
Feb 11 2015 18:23
@joneshf, I've realized that Ramda already dispatches to filter (https://github.com/ramda/ramda/blob/v0.9.1/src/filter.js#L28) so all we'd need to do to get mfilter behaviour is have Just and Nothing each provide a filter method. Does this sound reasonable?
Hardy Jones
@joneshf
Feb 11 2015 21:02
@davidchambers oh, cool. Then yeah there you go. That sounds like it should work.
you'd probably want to make sure some laws hold though
R.filter(p, R.map(f, m)) == R.map(f, R.filter(R.pipe(f, p), m))
R.filter(p, R.filter(q, m)) == R.filter(R.or.ap(p).ap(q), m)
assuming you have functions with Apply