These are chat archives for ramda/ramda

17th
Dec 2017
Arbaaz
@arbz__twitter
Dec 17 2017 10:14
@franciscotln @alavkx Thanks.
Jonah
@jonahx
Dec 17 2017 21:28

Consider:

const normalize = ap(flip(map), pipe(apply(Math.max), flip(divide)))
normalize([1,2,3]) // [0.3333333333333333, 0.6666666666666666, 1]

Now let instead of an array of values, we have an array of objects like [{a: 1, b: 99}, {a: 2, b: 1}] and we wish to normalize all the values of a. I feel like I should be able to do this with lenses, but I can’t see how to…. I’d like a compact point free solution, in any case.

Jonah
@jonahx
Dec 17 2017 21:37
I think the answer is to map a view, normalize, and then map a set
Jonah
@jonahx
Dec 17 2017 22:11
This does it:
const d = [{a: 1, b: 99}, {a: 2, b: 1}]
ap(flip(zipWith(set(aLens))), pipe(map(view(aLens)), normalize))(d)
// => [{"a": 0.5, "b": 99}, {"a": 1, "b": 1}]
Jonah
@jonahx
Dec 17 2017 23:57
alternatively:
ap(flip(zipWith(assoc('a'))), pipe(pluck('a'), normalize))(d)