These are chat archives for ramda/ramda

8th
Dec 2017
Mike Lambert
@lax4mike
Dec 08 2017 14:43
whoa, that's crazy
Mike Lambert
@lax4mike
Dec 08 2017 14:50
is this something that should be fixed?
Brad Compton (he/him)
@Bradcomp
Dec 08 2017 16:48
It's an inherent feature of Javascript.
Jonathan Chang
@jdkschang
Dec 08 2017 17:22
@Bradcomp not a :bug:
Michael Hurley
@buzzdecafe
Dec 08 2017 18:27
if someone can recommend a reliable way to fix that, i am all ears. the essence of the problem is we don't know how to get an empty instance of the accumulator, which could be anything
Brad Compton (he/him)
@Bradcomp
Dec 08 2017 18:35
The 'reliable' way to fix it would be to clone the initial accumulator. This is problematic too though because it means the user can't mutate the accumulator, along with the perf benefits. Also I don't know how cloning effects the prototype chain.
PS I am not actually suggesting we do that.
Michael Hurley
@buzzdecafe
Dec 08 2017 20:24
@Bradcomp if my accumulator is something like {evens: [0], odds: [1], thing: MyCustomThing} how are we to know how to clone that?
Brad Compton (he/him)
@Bradcomp
Dec 08 2017 20:29
That's the point of my comment on the prototype chain. We'd have to use R.clone on everything that comes in and hope it works properly
Personally, I think it's a better idea to leave it as is. Ramda doesn't mutate your input, but the user can do what they want.
Michael Hurley
@buzzdecafe
Dec 08 2017 20:48
yeah, sucks for cases like the one that precipitated this conversation though. it's not obvious what is going wrong :-(
Mike Lambert
@lax4mike
Dec 08 2017 21:11
why is there a mergeDeepRight and mergeDeepLeft?
couldn't you just change the order of the arguments just like merge?
Neeraj Singh
@neerajdotname
Dec 08 2017 21:11
Help needed in figuring out why allPass is not working. https://jsfiddle.net/et1vLq0s/1/
Vasili Sviridov
@vsviridov
Dec 08 2017 21:12
.allPass(steps.map(isPassed))?
Mike Lambert
@lax4mike
Dec 08 2017 21:13
yeah, R.allPass([R.map(isPassed)])
wait, that's not working either
Vasili Sviridov
@vsviridov
Dec 08 2017 21:14
(records)=>allPass(map(isPassed, records))
can't really point-free since the argument goes to inner fn
Nick McCurdy
@nickmccurdy
Dec 08 2017 21:15
@lax4mike Based on the docs that's the only difference so I think you're right, it's probably just a convenience for flipping arguments. But it's oddly inconsistent that there are two versions of mergeDeep but not merge
Mike Lambert
@lax4mike
Dec 08 2017 21:15
yeah, that's what i was thinking
Nick McCurdy
@nickmccurdy
Dec 08 2017 21:20
It seems like they discussed this in the mergeDeepRight/mergeDeepLeft PR, a bit long but I'm reading it now
ramda/ramda#1867
Neeraj Singh
@neerajdotname
Dec 08 2017 21:20
Sorry. I'm still not following it. My usage of allPass is pretty similar to what is mentioned in the docs. In the case of R.map(isPassed, records) looks like I'm iterating over the records before passing info to allPass.
Mike Lambert
@lax4mike
Dec 08 2017 21:23
const steps = [ 
  {name: "John", status: "passed"},
  {name: "Mike", status: "passed"}
]
// task is to find out if all objects have status "passed" or not

const isPassed = R.all(R.propEq("status", "passed"));
const allRecordsHaveStatusPassed = R.allPass([isPassed]);
const result = allRecordsHaveStatusPassed(steps);
Vasili Sviridov
@vsviridov
Dec 08 2017 21:23
@neerajdotname you're converting array of records to array of testing functions, and then allPass runs them all to ensure they all return true
Mike Lambert
@lax4mike
Dec 08 2017 21:23
you needed R.all
Nick McCurdy
@nickmccurdy
Dec 08 2017 21:23
@lax4mike It looks like they just merged in mergeLeft and mergeRight, probably deprecating merge with the next release. So I think it'll be consistent. :) ramda/ramda#2365
Mike Lambert
@lax4mike
Dec 08 2017 21:24
oh, interesting
i don't think i like that though...
Nick McCurdy
@nickmccurdy
Dec 08 2017 21:24
I'd rather have merge and mergeDeep but whatever
Mike Lambert
@lax4mike
Dec 08 2017 21:25
me too
Nick McCurdy
@nickmccurdy
Dec 08 2017 21:25
Especially since it's reduce not reduceRight
Neeraj Singh
@neerajdotname
Dec 08 2017 21:25
Got it. Thanks everyone.
Alex G Rice
@guidorice
Dec 08 2017 21:26
Hi all, learning ramda here. Here is a puzzler for me. how can you express this problem without using an arrow function? ie I would like to simplify this as much as possible, maybe use a builtin ramda function instead. What's most ramda ish?
const model = [2, 4, 6, 8];
R.all(val => R.contains(val, model))([2, 8]);
// true
R.all(val => R.contains(val, model))([0, 7]);
// false
Mike Lambert
@lax4mike
Dec 08 2017 21:26
you can use R.__ as a placeholder
R.all(R.contains(R.__, model))
Vasili Sviridov
@vsviridov
Dec 08 2017 21:26
@neerajdotname i think in your case allPass makes more sense if each record has multiple conditions, if it only has one - mapping with isPassed and passing to all seems fine
Neeraj Singh
@neerajdotname
Dec 08 2017 21:28
Didn't know about all. Will check it out. Thanks.
Alex G Rice
@guidorice
Dec 08 2017 21:28
@lax4mike :+1: thanks that works
Brad Compton (he/him)
@Bradcomp
Dec 08 2017 21:46

I'd rather have merge and mergeDeep but whatever

Me too!

@guidorice You can also use flip
const containedIn = R.flip(R.contains);

R.all(containedIn(model))([2, 8]);
Alex G Rice
@guidorice
Dec 08 2017 22:02
@Bradcomp cool- thanks for that too. That is more readable.
Mike Lambert
@lax4mike
Dec 08 2017 22:27
@Bradcomp it looks like there wasn't too much discussion about mergeLeft, etc. why was it decided to add those?
Brad Compton (he/him)
@Bradcomp
Dec 08 2017 22:29
Dunno, people seemed to want them
Mike Lambert
@lax4mike
Dec 08 2017 22:30
we're 3 for 3 who don't in this convo...
Heber Nobre
@zbrukas
Dec 08 2017 23:36
const obj = { a: 0, b: 1, c: 2};
const prepareSource = compose(
  dissoc('c'),
  set(lensProp('f'), view(lensProp('c'))),
  merge({ d: 3 }),
  pickAll(['a', 'b', 'c'])
);
Can someone guide me? I’m trying to copy the contents of prop c to prop f, but the result ends being {"a": 0, "b": 1, "d": 3, "f": function r(e){return 0===arguments.length||n(e)?r:t.apply(this,arguments)}}
Denis Stoyanov
@xgrommx
Dec 08 2017 23:41
@zbrukas
const obj = { a: 0, b: 1, c: 2};
const prepareSource = compose(
  dissoc('c'),
  lift(set(lensProp('f')))(view(lensProp('c')), identity),
  merge({ d: 3 }),
  pickAll(['a', 'b', 'c'])
);

prepareSource(obj)
Heber Nobre
@zbrukas
Dec 08 2017 23:41
Wow
@xgrommx please explain to me please what you did
I want to learn
Denis Stoyanov
@xgrommx
Dec 08 2017 23:42
or
const obj = { a: 0, b: 1, c: 2};
const prepareSource = compose(
  dissoc('c'),
  ap(flip(set(lensProp('f'))))(view(lensProp('c'))),
  merge({ d: 3 }),
  pickAll(['a', 'b', 'c'])
);

prepareSource(obj)
@zbrukas so, we need x => set(lensProp('f'), view(lensProp('c'), x), x)
or x => set(lensProp('f'))(view(lensProp('c')(x))(x)
Heber Nobre
@zbrukas
Dec 08 2017 23:43
Right
Denis Stoyanov
@xgrommx
Dec 08 2017 23:44
ap = g => f => x => g(x)(f(x))
Heber Nobre
@zbrukas
Dec 08 2017 23:45
Ok
And flip?
To change args order?
Denis Stoyanov
@xgrommx
Dec 08 2017 23:46
flip = x => y => v => x(v)(y)
Mike Lambert
@lax4mike
Dec 08 2017 23:46
you can also use assoc and prop instead of lens
obj => R.assoc("f", R.prop("c", obj), obj),
Heber Nobre
@zbrukas
Dec 08 2017 23:47
Yes, looks cleaner
Denis Stoyanov
@xgrommx
Dec 08 2017 23:48
ap(flip(assoc("f")), prop("c"))
Heber Nobre
@zbrukas
Dec 08 2017 23:50
@xgrommx where do you get that function flow? Ramda only has ((a, b, c, …) → z) → (b → a → c → … → z)
Denis Stoyanov
@xgrommx
Dec 08 2017 23:51
@zbrukas sorry?
Heber Nobre
@zbrukas
Dec 08 2017 23:51
This => flip = x => y => v => x(v)(y)
Denis Stoyanov
@xgrommx
Dec 08 2017 23:52
ramda has flip
Heber Nobre
@zbrukas
Dec 08 2017 23:52
Yes, I mean the definition
params + return
Denis Stoyanov
@xgrommx
Dec 08 2017 23:53
this is classic version of flip or C combinator
Heber Nobre
@zbrukas
Dec 08 2017 23:54
Yes, I’m too vanilla to FP, so I’m trying to learn where can I find the blueprints for those combinators
The signatures, I mean
Didn’t remember the word
Heber Nobre
@zbrukas
Dec 08 2017 23:55
Thanks