These are chat archives for ramda/ramda

19th
Dec 2016
Zhiliang Ong
@ongzhiliang
Dec 19 2016 03:35
@Bradcomp Thanks very much, it's indeed R.invoker that I needed
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:11
That's awesome @xgrommx :D
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:12
Hi there! How should I update value in object with nested arrays? Eg. I have { key: [ { key2: 'value' } ]}and I want to change with path [key, index, key2]. I've tried assocPath, but it converts arrays into objects.
Denis Stoyanov
@xgrommx
Dec 19 2016 12:18
@Avaq yes )
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:19
@stepankuzmin You could compose a Lens for this job, or nest some evolve and update.
Denis Stoyanov
@xgrommx
Dec 19 2016 12:19
@stepankuzmin evolve?
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:19
evolve converts array to object too
I'm trying to build lens composition
Denis Stoyanov
@xgrommx
Dec 19 2016 12:20
@stepankuzmin please provide some code in ramda repl
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:21
@ram-bot
R.evolve({a: { 0: { b: R.always(456)}}}, { a: [{ b : 123 }]})
Denis Stoyanov
@xgrommx
Dec 19 2016 12:21
@stepankuzmin what u expected?
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:22
I'm expecting { a: [{ b : 456 }]}, but result is { a: { 0: { b : 456 }}}
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:23
@stepankuzmin evolve expects an Object, and returns an Object. Since Arrays in JS are also Objects, it simply applies the same logic that it would to any object, and therefore turns it into an object. You might want to have a look at...:
R.adjust
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:23
Yep, but how should I deal with nested structure? When object has array of objects etc
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:25
@ram-bot evolve({ a: adjust( evolve({ b: inc }), 1 ) }, {a: [{b: 1}, {b: 2}, {b: 3}]} )
ram-bot
@ram-bot
Dec 19 2016 12:25
{ a: [ { b: 1 }, { b: 3 }, { b: 3 } ] }
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:25
Note how the second node was changed.
If you mean by "nested" that it could be either an Object or an Array, you'll need to put some kind of branching logic in there. If it's arbitrarily deep, you'll need to make it recursive.
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:29
Yep, but I think lens composition is more readable
Something like this
var lens = R.compose(
  R.lensProp('features'),
  R.lensIndex(0),
  R.lensPath(['properties', 'prop']));
Aldwin Vlasblom
@Avaq
Dec 19 2016 12:53
I agree, plus you can separate the code that determines your data-structure more neatly from the code that processes it.
Stepan Kuzmin
@stepankuzmin
Dec 19 2016 12:58
Yep, thanks!
Edward Mulraney
@edmulraney
Dec 19 2016 16:25
what's the name of this function:
const reduceRest = reducer => xs => reduce(reducer, head(xs), tail(xs))
i've called it reduceRest but i'm assuming this is a common use and already has a name?
example usage:
const commaSeparate = reduceRest((p, c) => `${p}, ${c}`)
commaSeparate(["a", "b", "c"])
Syaiful Bahri
@syaiful6
Dec 19 2016 17:32
if empty then that function will fail?
foldl1 not so good name though.. :smile:
Edward Mulraney
@edmulraney
Dec 19 2016 17:48
okay so nothing defined within ramda already then?
Kliment Mamykin
@kmamykin
Dec 19 2016 20:30
Is there a function that is like R.join, but returns a list, e.g. ???('|', ['a', 'b', 'c']) => ['a', '|', 'b', '|', 'c']
Denis Stoyanov
@xgrommx
Dec 19 2016 20:35
Kliment Mamykin
@kmamykin
Dec 19 2016 20:35
Awesome! Thanks @xgrommx