These are chat archives for ramda/ramda

25th
Oct 2017
James Forbes
@JAForbes
Oct 25 2017 02:07
I think if ramda 1.0/2.0/n moved to manually curried unary functions, and internally inlined what would normally be a composed helper utility - this problem would largely resolve itself.
Arti Villa
@artivilla
Oct 25 2017 05:30
hi guys, new to this, how do i extract the obj from localStorage.sites thats an array with a prop called domains but the domains is a list itself: return R.find(R.propEq('domains', tabURL))(JSON.parse(localStorage.sites))
the propEq actually needs to do a nested search or at least 1 level down rather than search like a key/value pair .
Sean Cannon
@SeanCannon
Oct 25 2017 05:38

@skatcat31 Yea use R.ifElse. Example :

const foo        = 'some stuff';
const condition1 = true;
const condition2 = false;

const logger = id => R.prepend(`${id} - `);

R.compose(
  R.join(' '),
  R.ifElse(R.always(condition2), R.tap(logger(2)), R.identity),
  R.map(R.toUpper),
  R.ifElse(R.always(condition1), R.tap(logger(1)), R.identity),
  R.split(' ')
)(foo);

https://goo.gl/Jepd4x

Sean Cannon
@SeanCannon
Oct 25 2017 05:44
@artivilla Are you storing stuff on the localStorage object? Are you not doing localStorage.setItem('sites', ['...']) and localStorage.getItem('sites') ? Anyway checkout R.pathEq - I'm not really sure what your data structure looks like... array with a prop.. ?
Arti Villa
@artivilla
Oct 25 2017 05:46
trying to do something like this: https://goo.gl/cL7s9g
nice!
that’s what i needed
Sean Cannon
@SeanCannon
Oct 25 2017 05:49
Here you go https://goo.gl/QiqgRd
Arti Villa
@artivilla
Oct 25 2017 05:51
oh wow, that’s even cleaner. hopefully i can get that comfortable :)
Sean Cannon
@SeanCannon
Oct 25 2017 05:53
The repl is your best friend :) Give it time - also there's a nice wiki which helps people find functions in the library https://github.com/ramda/ramda/wiki/What-Function-Should-I-Use%3F
Arti Villa
@artivilla
Oct 25 2017 06:07
oh wow, i didn’t come across this. thanks!
Rolf Strijdhorst
@rolfst
Oct 25 2017 08:05
@SeanCannon @skatcat31 you can change R.always(condition2) to R.F and R.always(condition1) to R.T to make it more conchise
Jonah
@jonahx
Oct 25 2017 08:10

I want a fully general version of useWith (read: one that works for functions of any number of args) which transforms only the argument in the final position. That is:

transformLast = (fn, transformFn) => useWith(fn, [identity, identity, …, transformFn])

Obviously the syntax won’t work, but that’s the idea. Is it possible to write a general version like that in ramda or would you need to specify that number of args?

Kurt Milam
@kurtmilam
Oct 25 2017 09:31
@jonahx I'd probably look at using reduce rather than useWith.
Thanks all for the comments on yesterday's article. I also find his assertion that using Maybe will lead to code bloat, especially in comparison to an imperative implementation.
James Forbes
@JAForbes
Oct 25 2017 13:19
just a simple misunderstanding @SeanCannon
Sean Cannon
@SeanCannon
Oct 25 2017 14:00
I think it’s a deeper misunderstanding; give me another example where you’d ever use R.T or R.F with R.ifElse as the first param.
Rolf Strijdhorst
@rolfst
Oct 25 2017 15:26
@SeanCannon isn't R.always(true) the same as R.T?
Jonah
@jonahx
Oct 25 2017 15:54
@rolfst yes
Kurt Milam
@kurtmilam
Oct 25 2017 16:01
@rolfst I think the idea was that condition1 might be something like debug or process.env.NODE_ENV === 'development'.
Thus giving you a way to configure whether anything was logged based on an environment variable.
Rolf Strijdhorst
@rolfst
Oct 25 2017 16:02
ah I see ok
Levi Robertson
@lvrbrtsn
Oct 25 2017 20:30
hello all! I have a (hopefully) quick question. I am mapping over an object to create an array of object 'names'. This seems to return some sort of iterable, but I specifically need it to be an Array for react to play nice. What is the best way to do this?
Levi Robertson
@lvrbrtsn
Oct 25 2017 20:33
That was my first attempt, but the array that returns is empty which led to me being even more confused. the object Ramda returns for sure should work with that method though?
Robert Mennell
@skatcat31
Oct 25 2017 20:33
you said it was an iterable. Which Ramda function are you suing?
Levi Robertson
@lvrbrtsn
Oct 25 2017 20:33
map
im not sure what its returning, my console just says 'Object' and that object has keys 1, 2, 3, ect.
Robert Mennell
@skatcat31
Oct 25 2017 20:35
map over an Object returns an Object according to the documentation
var double = x => x * 2;

R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6}
From ducomentation. If you want an array of values form that you can do Object.values after you've mapped over the object. It will have an array of values
Object.values(R.map(double, {x: 1, y: 2, z: 3})); //=> [2, 4, 6]
Levi Robertson
@lvrbrtsn
Oct 25 2017 20:38
perfect! Thanks a ton!
Robert Mennell
@skatcat31
Oct 25 2017 20:38
R.pipe(R.map(double), Object.values)({x: 1, y: 2, z: 3}); //=> [2, 4, 6]
I spent way to long trying to find that for it to have such a simple and clear name lol
maybe its time for a break. Thanks Robert!
Julian Coleman
@juliancoleman
Oct 25 2017 21:46

Hey, guys. I was here a couple weeks ago, asking about a reference to indexBy. I wanted to turn an array of objects into an object of objects, where a specified key would be the key, and the value would be the rest of the object. This was achieved with the following code

const indexByKey = key => R.pipe(
  R.indexBy(R.prop(key)),
  R.map(R.omit([key]))
);

And would result in [{ name: "J. Coleman", id: "5"}]; becoming { 5: { name: "J. Coleman"} };

My question is how might I reverse this process now?

Brad Compton (he/him)
@Bradcomp
Oct 25 2017 21:52
@juliancoleman Do you mean like this :question:
Julian Coleman
@juliancoleman
Oct 25 2017 21:53
Yes
You are a saint
thank you
Could you give me some insight on how you're able to pass an array into map?
I assume that's a destructure, yeah?
Brad Compton (he/him)
@Bradcomp
Oct 25 2017 21:55
Yes, I am just destructuring the pair
without the destructuring it would look like: map(pair) => assoc('id', pair[0], pair[1]))
Julian Coleman
@juliancoleman
Oct 25 2017 21:57
I had absolutely no idea you could do that. That's what was blocking me because just a simple console.log would only log out the value, not the key. But since commenting out the map, it looks like the indexability comes from toPairs itself. That is GENIUS
Brad Compton (he/him)
@Bradcomp
Oct 25 2017 22:01
:bowtie:
Jonathan Chang
@jdkschang
Oct 25 2017 22:40
the bowtie saint