These are chat archives for ramda/ramda

25th
Feb 2018
jy95
@jy95
Feb 25 2018 02:23
Hello, I have a project where I often use reduce,map,filter operations on ES6 Map/Set . I would like to know if someone has a idea what could be the performance improve if I switch parts like that in Ramba : https://github.com/jy95/mediaScan/blob/master/src/filters/filterProperties.ts#L109 ? Thanks
Yazeed Bzadough
@yazeedb
Feb 25 2018 04:47
Hey everyone, had no idea this chat existed :D
I just published a Medium article on Redux + Ramda and would love your feedback
functionalStoic
@functionalStoic
Feb 25 2018 06:34
@yazeedb Good stuff. Enjoyed a few of your other posts as well. Thanks!
Julien Gonzalez
@customcommander
Feb 25 2018 09:04

Hi all,

I'm having a hard time building a transducer.
I do get the idea (I think) I just seem unable to create one.

I've got an array of functions. Each function returns a string.
I'd like to iterate over that array until one function returns a non-empty string.
(Which seemed like a job for R.into to me.)

const a = x => '';
const b = x => 'foo';
const c = x => 'bar';

R.into('', transducer, [a, b, c]);
//=> 'foo'

For transducer I've got:

// apply 1 to each function in the array
// if the result is empty, return an empty string
// otherwise wrap the result within R.reduced to stop iterating
R.compose(R.ifElse(R.isEmpty, R.always(''), R.reduced), R.applyTo(1))

I've tried multiple variations of this. I always ended up with one of these errors:

  • TypeError: f is not a function
  • TypeError: xf.@@transducer/step is not a function

Any help would be appreciated :)

Cheers,

Joey Figaro
@joeyfigaro
Feb 25 2018 16:24
Sharing on REPL broken for anyone else?
I have an array of three objects that have the following shape: { 'hasdfh9asdfh': { ... } } … each object in the array has the same key (hasdfh9asdfh), but uniq doesn't trim the list down to one object. Anyone have any tips on using uniqBy and / or uniqWith?
Scott Sauyet
@CrossEye
Feb 25 2018 16:54
@joeyfigaro: REPL sharing is working for me. Every now and then it has issues, and it likely will fail with very large code blocks, as the entire code is stored in a URL, which the Google shortener doesn't like beyond some specific size.
If I understand, you REPL code, you have something like [{abc: {foo: 1}}, {abc: {bar: 2}}, {abc: {baz: 42}}] and you want uniq or some variant to combine them into one?
If that's correct, it seems somewhat odd.
Scott Sauyet
@CrossEye
Feb 25 2018 17:00
But if those are the only keys in the outer objects, then uniqBy(keys) would probably do it.
joao@kapmug
@jay-jlm
Feb 25 2018 18:15
Hey guys, what's up with R.and(true, 1) returning a non Boolean value?
I mean I suppose it's because of how js works... but it looks to me the documentation is misleading here
hmm... ramda/ramda#1979
Francisco
@franciscotln
Feb 25 2018 18:19
@yazeedb good article. I'd just comment on one thing:
the name of that findItemById function doesn't sound right for me because it's not a finder, find something for me means find it and return it to me so I'm expecting an object but this returns a boolean, it's a predicate so I'd name it idEq or something like that and the definition you gave using fat arrows can be replaces just by const idEq = R.propEq('id');. I also noticed that you used it passing obj.id so you can make use of R.eqProps('id') and pass both object not having to worry to "dot id" on it.
const items = [
  { id: 1, value: 0 },
  { id: 2, value: 0 },
  { id: 3, value: 0 },
];

const newItem = { id: 1, value: 2.71828 };

R.map(R.when(R.eqProps('id', newItem), R.always(newItem)), items);
Simon Friis Vindum
@paldepind
Feb 25 2018 18:21
Yeah. R.and works similarly to true & & 1. It's something that has been discussed in the past.
joao@kapmug
@jay-jlm
Feb 25 2018 18:21
right but that is not what the description says
Returns true if both arguments are true; false otherwise. << ouch.. how is that not misleading here??
it's literary telling me that it will either return a value of 'true' or it will return 'false'.. how is that even debatable ?
Mike Lambert
@lax4mike
Feb 25 2018 18:24
hmm yeah, that documentation should be updated: https://github.com/ramda/ramda/blob/v0.25.0/source/and.js
or the function should change to check for strictly true/false
but, i guess the @retuns is correct
@return {Any} the first argument if it is falsy, otherwise the second argument.
functionalStoic
@functionalStoic
Feb 25 2018 18:27
What does the {Any}/first clause mean?
Mike Lambert
@lax4mike
Feb 25 2018 18:27
the arguments can be of Any type
Francisco
@franciscotln
Feb 25 2018 18:28
@customcommander I think it's not for transducer, it's for R.find
https://goo.gl/ERgstC
Simon Friis Vindum
@paldepind
Feb 25 2018 18:35
@jay-jlm Yes. You are definitely right. That is misleading and should be fixed.
joao@kapmug
@jay-jlm
Feb 25 2018 18:45
@paldepind , I've made a request to reopen this issue , please upvote or add your request too: ramda/ramda#1979
is there someone I should mention this to? maybe @CrossEye ?
Yazeed Bzadough
@yazeedb
Feb 25 2018 19:11
@functionalStoic Thank you for checking them out!
@franciscotln Thank you for the detailed feedback. I'll definitely update my post with this info. What social media handle(s) can I use to credit you?
Francisco
@franciscotln
Feb 25 2018 19:37
That's me on twitter @yazeedb : @tavaresn ( - :
Joey Figaro
@joeyfigaro
Feb 25 2018 20:05
@CrossEye Would not disagree—the incoming/raw data is a nightmare, and the best I've managed to get massaging it is an array of potentially identical objects. Giving uniqBy(keys) a shot—thank you!
Xiaoyu Li
@xiaoyu-tamu
Feb 25 2018 21:33
Hi guys, what difference between use transducer and call composed function directly?

var numbers = [1, 2, 3, 4];
var transducer = R.compose(R.map(R.add(1)), R.take(2));
var ret1 = transducer(numbers);
var ret2 = R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3]
console.log(ret1)
console.log(ret2)

they both return same result

Francisco
@franciscotln
Feb 25 2018 22:18
@xiaoyu-tamu it happens to give the same result in this example you gave, but let me give a more general example where the results are different and try to explain the difference: https://goo.gl/GfzoBv
Please check the link. You'll see that not only the results are different but also the numbers of iteration over the collection is different.
Transducers are 🔥💪
Xiaoyu Li
@xiaoyu-tamu
Feb 25 2018 23:46
@franciscotln Thank you for such nice reply!