These are chat archives for ramda/ramda

13th
May 2015
Simon Friis Vindum
@paldepind
May 13 2015 06:53
What is the difference between doing `curryN(4, fn)` and `nAry(4, fn)`?
Scott Sauyet
@CrossEye
May 13 2015 11:26
@paldepind: Not too much if `fn` is curried. Both will have arity 4 and will behave much the same. But if `fn` is not a curried function, `curryN(4, fn)(a, b); //=> :: (c, d) -> fn(a, b, c, d)` whereas `nAry(4, fn)(a, b); //=> fn (a, b)`.
Simon Friis Vindum
@paldepind
May 13 2015 13:08
@CrossEye that sounds superfluous to me. Why not remove nAry?
Jethro Larson
@jethrolarson
May 13 2015 15:43
Let me see if I'm understanding this right. I can chain(Maybe.of, [1,2]) and I'll get [Just(1),Just(2)]?
Dalibor Novak
@BorePlusPlus
May 13 2015 15:46
Do we have something like list comprehensions in ramda?
Hardy Jones
@joneshf
May 13 2015 15:46
@jethrolarson No, you should not be able to do that. If you can, something is broken.
Dalibor Novak
@BorePlusPlus
May 13 2015 15:47
or anything that will take 2 lists and give me all permutations (as pairs) of their elements?
Hardy Jones
@joneshf
May 13 2015 15:47
@jethrolarson what you just wrote there is `sequence (traverse Just [1, 2])`, though that could be inlined probably
@BorePlusPlus you can use the `Apply` instance of `Array` to do that.
Dalibor Novak
@BorePlusPlus
May 13 2015 15:49
@joneshf care to elaborate?
Hardy Jones
@joneshf
May 13 2015 15:49
@BorePlusPlus assuming you mean the cartesian product when you say "permutations (as pairs)".
Jethro Larson
@jethrolarson
May 13 2015 15:50
R.xprod do what you want?
Hardy Jones
@joneshf
May 13 2015 15:50
@BorePlusPlus sure, ^
:)
Dalibor Novak
@BorePlusPlus
May 13 2015 15:50
yes I am looking for cartesian product
tip-top boys - full of win
:)
cheers
Dalibor Novak
@BorePlusPlus
May 13 2015 15:57
while I'm here - best way to sort array of strings? R.sort(R.identity) is not really doing it :)
OK got it sortBy did the trick
Scott Sauyet
@CrossEye
May 13 2015 16:11
@paldepind: useful for creating functions of fixed arities, regardless of whether you want to curry then.
Hardy Jones
@joneshf
May 13 2015 16:24
@jethrolarson what you want is something like this: http://bit.ly/1IxXWav
or alternatively...
Dalibor Novak
@BorePlusPlus
May 13 2015 16:30

sorry to keep pestering you guys, but why is this

``R.converge(R.map, R.append, dateFieldPairs)(data);``

not giving me same results as this

``R.map(R.append(data), dateFieldPairs(data))``
?
shouldn't it do the same thing?
Simon Friis Vindum
@paldepind
May 13 2015 16:31
@CrossEye But why would currying ever be a problem?
The only vacate where currying could be a problem is for variadic functions. But then you wouldn't be using any of the functions.
David Chambers
@davidchambers
May 13 2015 17:30
@BorePlusPlus, those expressions should be equivalent. What are the values of `dateFieldPairs` and `data`?
@paldepind, I agree that it feels wasteful to have `R.arity`, `R.nAry`, and `R.curryN`. I realize they perform slightly different roles, but I wonder whether we really need all three functions.
Chet Harrison
@ChetHarrison
May 13 2015 19:43

hey all. I have been refactoring some code in the functional style. It's been fun but now I'm running into some more complex issues and would love any feedback.

I have some code that mixed Backbone's `on`, `off`, and `trigger` methods onto a object along with an RxJs `Observable`. All events are forwarded into its Observable Event stream. Then the Observable is registered with a root-level "AppBus" collection with a name key. Any other code that wants to subscribe to another module's events can grab the Observable ref from the AppBus. The Observable will publish till a `destroy` event and then unsubscribe all listeners, remove and null the Observable from the AppBus. This way I can make any Backbone/Marionette Object "Observable".

ok sorry that was a bit much.

The question is how to implement the AppBus registry without mutation. It's going to need to hold and dispense the Observable refs.

Tobias Pflug
@gilligan
May 13 2015 21:54
Hm, how should I implement `either :: (a->c) -> (b->c) -> Either a b -> c` with ramda-fantasy - there is no isLeft or isRight
David Chambers
@davidchambers
May 13 2015 21:56
I’m not sure. Could you implement it in terms of `bimap`?
I’m clearly biased, but I prefer Sanctuary’s approach which is to have `Left` and `Right` as public constructor functions so one can use `R.is(S.Left)` and `R.is(S.Right)`.
Tobias Pflug
@gilligan
May 13 2015 22:01
would be okay with me I guess
quite enjoying ramda & ramda-fantasy at the moment ;]
David Chambers
@davidchambers
May 13 2015 22:05
That’s great!
Tobias Pflug
@gilligan
May 13 2015 22:06
will spend some more time on it, maybe i could do a pull request with some examples and/or docs
above all I feel a strong urge to replace all usage of lodash with ramda at work ;-)
David Chambers
@davidchambers
May 13 2015 22:29
I understand that urge. Spend some time teaching your colleagues the philosophy of Ramda so they become allies rather than obstacles.
Tobias Pflug
@gilligan
May 13 2015 22:31
yeah - actually the ones that are already using lodash will probably accept and like it I think
we'll see
David Chambers
@davidchambers
May 13 2015 22:31
I’m interested to hear how it goes.
Tobias Pflug
@gilligan
May 13 2015 23:20
```var tuples = files.chain( R.map(function (file) { return Tuple(file, fs.readFileSync(file, 'utf8')); }));```
hm, i can't write that more compactly or can I?
David Chambers
@davidchambers
May 13 2015 23:23

You could replace:

``function(file) { return Tuple(file, fs.readFileSync(file, 'utf8')); }``

with something like:

``R.converge(Tuple, R.identity, R.partialRight(fs.readFileSync, 'utf8'))``

It’s not necessarily any better, though.

Michael Hurley
@buzzdecafe
May 13 2015 23:24
``R.map(Tuple(R.__, fs.readFileSync(file, 'utf8')))```
oh, bugger, gotta get the second ref to `file`