These are chat archives for ramda/ramda

Dec 2015
Scott Christopher
Dec 24 2015 00:01
Yeah, the client needs to speak HTTP too.
require('http').createServer((req, res) => res.end('hello')).listen(8000)
❯ cat request.txt
GET / HTTP/1.1
Host: localhost

❯ cat request.txt | nc localhost 8000
HTTP/1.1 200 OK
Date: Thu, 24 Dec 2015 00:00:32 GMT
Connection: keep-alive
Content-Length: 5

Dec 24 2015 00:02
Scott Christopher
Dec 24 2015 00:03
require('net').createServer(conn => conn.write('hello')).listen(8000)
cat request.txt | nc localhost 8000
Lucas Feliciano
Dec 24 2015 14:21
Lucas Feliciano
Dec 24 2015 14:35
Guys, first of all marry chrismas.


I'm struggling trying to do something here:

I have a tri dimensional array and I want to change a atribute of a object that is inside the deepest array.
But by doing that I need to change the reference to their parents
To respect this scenario

initial state
| |\
D changes, all parents are replaced
B* C
|  |\
D* E F

What is the best approach to do that using ramda?

Niloy Mondal
Dec 24 2015 14:41
Why would A -> B change? Only B -> D should change
Lucas Feliciano
Dec 24 2015 14:48
because if the reference of B change, A needs to change as well
we know something has changed because A changed
we know something in B changed because b changed
we know everything below C hasnt changed because C hasnt changed
That is a react concept
How it compares the tree state
to calculate what need to be re rendered
Scott Sauyet
Dec 24 2015 15:33
assocPath works with plain objects, but not arrays. update and adjust work with arrays, but not nested ones. I think you're left with [lenses] (, which are very flexible and very powerful.
Lucas Feliciano
Dec 24 2015 15:36

Indeed, but I tried to use lens in the nested array and had no success, the references to their parents still the same. I even tried to compose lens but didnt work :(
I'm thinking to start to use Immutablejs.

The official documantation of redux suggest that.

Scott Sauyet
Dec 24 2015 15:39
I'm on my phone and can't easily test now, but they should work. I'll try to test when I'm in front of a computer.
Scott Sauyet
Dec 24 2015 15:46
Actually, maybe I misunderstood. Do the children maintain references to their parents? I know nothing that would deal with that.
Niloy Mondal
Dec 24 2015 15:57
@CrossEye Is there any plans to support Map where Object is supported by Ramda?
Scott Sauyet
Dec 24 2015 16:07
@niloy: I think that where we can find a reasonable abstraction they both follow, it would probably be worth doing.
Lucas Feliciano
Dec 24 2015 16:13
@CrossEye, no the children do not maintain references.
I need change reference for each parent
This message was deleted

lets say that I want to change the value of node h:

so my tree must be like that afterwards
That is what I'm trying to achieve
Scott Sauyet
Dec 24 2015 16:23
Right. assocPath does that fine for objects. If you need arrays, we haven't built in anything but lenses.
var orig = [[[{d: 1}]], [[{e: 2}], [{f: 3}]]];
var _0 = R.lensIndex(0);
var xProp = R.lensProp('x');
var dLens = R.compose(_0, _0, _0, xProp);

var result = R.set(dLens, 'foo', orig); 
//=> [[[{"d": 1, "x": "foo"}]], [[{"e": 2}], [{"f": 3}]]]
result[0] === orig[0]; //=> false
result[1] === orig[1]; //=> true
Brian Murphy-Dye
Dec 24 2015 16:27
Scott Sauyet
Dec 24 2015 16:38
But if they're plain objects, then assocPath is a nice shortcut:
var orig = {a: {d: 1}, b: 2, c: {e: 3, f: {h: 4, i: 5}, g: 6}};
var result = R.assocPath(['c', 'f', 'h'], 8, orig);
//=> {a: {d: 1}, b: 2, c: {e: 3, f: {h: 8, i: 5}, g: 6}}

orig.a === result.a; //=> true
orig.c === result.c; //=> false
orig.c.e === result.c.e; //=> true
orig.c.f === result.c.f; //=> false
orig.c.f.h === result.c.f.h; //=> false
orig.c.f.i === result.c.f.i; //=> true