These are chat archives for ramda/ramda

30th
Apr 2015
Hardy Jones
@joneshf
Apr 30 2015 02:18
makes sense
Simon Friis Vindum
@paldepind
Apr 30 2015 05:57
@JediMindtrick I've created a tiny library for diff'ing JSON objects: dffptch.
@buzzdecafe, @thecotne, Wouldn't a merge that just recurses into object be what people want?
Simon Friis Vindum
@paldepind
Apr 30 2015 06:02
@buzzdecafe, I'd certainly expect a 4x7 square. Actually I don't see the problem at all.
Brandon Wilhite
@JediMindtrick
Apr 30 2015 09:50
@paldepind Thanks, I'll take a look.
Simon Friis Vindum
@paldepind
Apr 30 2015 10:00
@JediMindtrick, no problem. The source is decently commented but feel free to ask if you have questions.
Brandon Wilhite
@JediMindtrick
Apr 30 2015 10:33
I've got two design questions, about Either
1) It seems like once you start using it in a codebase, it's maybe (probably) a good idea to use it consistently? (this is probably just a question of taste)
2) If we actually want an exception to be thrown in case of failure, it would seem like the thing to do would be to throw it in the error-handling function of Either?
I'm sure any thoughts on that would be heavily context-dependent and somewhat a matter of taste...but any useful insights here?
Raine Virta
@raine
Apr 30 2015 10:49
might've been covered already but i think generally you want to "stay inside" that Either type as long possible, and use the methods provided to perform computations on the data inside
Raine Virta
@raine
Apr 30 2015 10:54
when using data.maybe with react i was delighted to find out that i could render a Maybe type and it would not do anything in case of Nothing. similarly to how rendering an undefined value does nothing in react. so at no point did the value have to be extracted
Brandon Wilhite
@JediMindtrick
Apr 30 2015 11:16
that's pretty awesome about react...I'm currently an angular guy myself, but the more I learn about react, the more I realize I need to take a serious look at it
on current project I'm going to want to throw in some cases...it's a nodejs project and there will be times when I want the process to crash
my stack trace will probably get jacked-up though
Scott Sauyet
@CrossEye
Apr 30 2015 11:59
That shouldn't be anything specific to React, unless they've actually gone down the path of working directly with Maybe. If you simply map render over your Maybe, it should just work since map on a Nothing is a no-op.
@paldepind that misshapen square comment was mine. I do think it demonstrates the issues that can arise. The lodash implementation punts on this, handing it back to the user to solve. I suppose we could do the same, but it's trickier with our no-optional-arguments stance.
Brandon Wilhite
@JediMindtrick
Apr 30 2015 12:48
@CrossEye good point, in angular we'd probably just do this map when we're in the then() of an $http, at least that's what comes to my mind
Simon Friis Vindum
@paldepind
Apr 30 2015 13:01
@CrossEye Indeed it was. I did intent to direct my message at you.
@CrossEye I still really don't see the issue. If a user asks to recursively merge the properties from two objects together isn't he accountable for the result?

You can do equally odd things with the current merge:

var square = {w: 4, h: 4};
var newSquare = R.merge(square, {h: 7});

I don't see how that can be an issue with merge itself..

Scott Sauyet
@CrossEye
Apr 30 2015 14:01
@paldepind: but constructed objects might depends on their own invariants. What is the area of the new square? 16? 49? 28? It depends on how the area was implemented.
And if the property we copy is a function, do we inherit its closure? Can we? Do we want to? We can't help but inherit its static binding if it has one, which could be very disconcerting.
Simon Friis Vindum
@paldepind
Apr 30 2015 15:18
@CrossEye, how do those concerns not apply to the current merge?
If an object needs to maintain some invariants and those invariant could be broken by a merge then you wouldn't want to use neither merge nor deepMerge on it.
If you assign a function a an object the object will refer to the exact same function along with it's closure and bound context. That makes sense. That how it works in JS.
Scott Sauyet
@CrossEye
Apr 30 2015 15:54
This message was deleted
Our existing merge I suppose had the same issue at the top level, but we don't ever pretend to be doing more than a simple mixin of property names. I did say that I'd welcome a PR, but that I thought that there is a fair bit of subtle complexity lurking for an implementor.
Raine Virta
@raine
Apr 30 2015 17:45

playing around with transducers

var arr = [ { a: 1 }, { a: 2 }, { a: 3 } ];
var transducer = R.compose(R.map(R.prop('a')), R.filter(R.gt(R.__, 1)));
R.into([], transducer, arr);

what kind of reducer function do I need if I want to sum the result without an intermediate list?

R.into([]) won't work obviously
Hardy Jones
@joneshf
Apr 30 2015 17:48
can you just use R.sum?
Raine Virta
@raine
Apr 30 2015 17:52
R.transduce(transducer, R.add, 0, arr);
seems to work
@joneshf I could sum the result of into yeah if that's what you meant
Hardy Jones
@joneshf
Apr 30 2015 17:56
well i meant just tacking the sum onto the front of your composition
also, isn't that composition backwards?
Raine Virta
@raine
Apr 30 2015 17:58
transformers are composed backwards
for reasons which I don't fully understand yet
Hardy Jones
@joneshf
Apr 30 2015 17:58
oh?
joneshf @joneshf still hasn't looked into transformers
Hardy Jones
@joneshf
Apr 30 2015 17:59
...
no, gitter, that's not what i wanted
Raine Virta
@raine
Apr 30 2015 17:59
var transducer = R.compose(R.filter(require('treis')(R.gt(R.__, 1))), R.map(R.prop('a')));

f1 a: { a: 1 }
f1 => false
f1 a: { a: 2 }
f1 => false
f1 a: { a: 3 }
f1 => false
that's what I tried first until I remembered the compose backwards thing
Stephen Kamenar
@farzher
Apr 30 2015 19:41
contacts = R.sortBy (.confidence),  contacts
companyContacts = R.groupBy (.domain), contacts
I need the companyContacts keys to stay in the order they're inserted in by groupBy. But you can't trust js object key order. Any ideas?
Hardy Jones
@joneshf
Apr 30 2015 20:08
array?