These are chat archives for ramda/ramda

24th
Jan 2017
kid-icarus
@kid-icarus
Jan 24 2017 00:51
is there a way to have assoc use the value of an applied function for each time it's called? for instance, i have an array of circles and i want to map(assoc('color', getRandomColor()), circles)
instead, assoc always uses the first value from getRandomColor() call
oh wait, i should just pipe it
no i guess that won't do either
kid-icarus
@kid-icarus
Jan 24 2017 01:06
oh sweet, i finally needed a lens
was wondering when i'd eventually need to start using lenses
mikiubo
@mikiubo
Jan 24 2017 08:11
@artfuldev i want (f(3) == 'var ciao=4') f like above
Sudarsan Balaji
@artfuldev
Jan 24 2017 13:11
@mikiubo
const a = R.curry((v,x,n) => v+" "+x+"="+n);
const d = a('var');
const e = d('ciao');
const f = R.compose(e, R.inc);
f(3);
That's the best within R.compose. We can only compose when the functions take composable arguments. fog(x) only works when the output of f(x) is the only argument to g. What you're asking is like a compose where f(x) is the last argument tog, like g(...args,f(x)). In that case, why don't we write a function that takes f(x) as an argument itself?
Sudarsan Balaji
@artfuldev
Jan 24 2017 13:17
Let's introduce another param:
const a = R.curry((v,x,n) => v+" "+x+"="+n);
const _a = R.curry((v,x,f,n) => a(v,x,f(n)));
const d = _a('var');
const e = d('ciao');
const f = e(R.inc);
f(3);
if we don't need e(R.inc), we can always write e(R.identity)
mikiubo
@mikiubo
Jan 24 2017 13:21
@artfuldev thanks a lot
Sudarsan Balaji
@artfuldev
Jan 24 2017 13:23
This is another way:
const a = (v,x,n) => v+" "+x+"="+n;
const b = (v,x,f,n) => a(v,x,f(n));
const c = R.curry(b)(R.__, R.__, R.inc);
const d = c('var');
const e = d('ciao');
e(3);
@mikiubo any time :)
In the latest solution, we fix the value of the f argument to function b to be R.inc. Depending on your requirement, you can fix it or partially apply it later
Alex Deas
@alex-deas
Jan 24 2017 20:22
Hi guys, I'm currently writing flow types for v0.23.0 and I've come across a mention of Ord in the signature for ascend (http://ramdajs.com/docs/#ascend). I'm not really sure on what that means in this context though though. From what I can gather through the rest of the docs it might relate to posets, however I'm not sure. Could someone enlighten me on what it means in the context of a function signature?
Kevin Wallace
@kedashoe
Jan 24 2017 21:31
@alex-deas it doesn't mean much in this context :) we don't actually very that b satisfies Ord, it is just to let the user know that their function should return something that can be compared using the native comparison operators (ie >, ==) etc
not sure if that has any implications for flow types
(and by "their function", I meant the first argument to ascend)
Alex Deas
@alex-deas
Jan 24 2017 21:35
Ah ok, that clears it up. Thanks :thumbsup: