These are chat archives for ramda/ramda

27th
Mar 2019
Emilio Srougo
@Emilios1995
Mar 27 00:00

Hi, how would you do the following with Ramda?
I have an object:

{
  items: [{}, {}, {}]
}

and want to end up with:

{
  items: [{}, {}, {}],
  itemsCount: 3
}
Matthew Willhite
@miwillhite
Mar 27 04:56
const input = { items: [{}, {}, {}] };

const itemsWithCount =
  R.pipe ( R.prop ('items')
         , R.applySpec ({ items: R.identity
                        , itemsCount: R.length
                        })
         );

itemsWithCount (input);
//=> { items: [ {}, {}, {} ], itemsCount: 3 }
David Sancho
@davesnx
Mar 27 09:42

Hey, I'm working on a learning tool for new users of ramda and tries to improve the documentation of ramda.

The prototype looks like that: https://my.mixtape.moe/yujhrn.webm

I used the content from What Function Should I Use https://github.com/ramda/ramda/wiki/What-Function-Should-I-Use
Do I need to speak to anyone to not violate any licence?
David Sancho
@davesnx
Mar 27 10:23
Stefano Vozza
@svozza
Mar 27 10:57
this seems like a great idea! although the mymixtape link is timing out
David Sancho
@davesnx
Mar 27 10:58
Let me change it to the github gif
Stefano Vozza
@svozza
Mar 27 10:58
ah that’s great
this is actually the sort of thing i had in mind when i wrote the What Function doc but my frontend skills just weren’t up to the task
David Sancho
@davesnx
Mar 27 11:00
I didnt know that you write that!
I just give kudos on the readme to "Jan Killian" for being the latest editor
Stefano Vozza
@svozza
Mar 27 11:01
oh that’s weird all the edit history is gone, there used to be like 15-20 revisions
ah there’s a double link
one that ends in a question mark
David Sancho
@davesnx
Mar 27 11:02
True, now I can see the history!
Stefano Vozza
@svozza
Mar 27 11:03
that’s still really weird, need to fix it back
Ah wait: Remove question mark in page name to allow cloning the wiki on Windows
David Sancho
@davesnx
Mar 27 11:04
What I want to do is to elavorate on a simpler examples
rather than use the ones from the docs
Stefano Vozza
@svozza
Mar 27 11:06
Yeah, makes sense
David Sancho
@davesnx
Mar 27 11:06
and ofcourse, make a better design :D
Coder
@coder6421_gitlab
Mar 27 19:15
Hi guys! I'm stuck mentally. I have a list of objects of various types. I'd like to apply functions for processing based on their types which I can determine with a specific key on each object. Currently I'd use a switch and call the appropriate function, but does anyone have a more elegant idea?
Brad Compton (he/him)
@Bradcomp
Mar 27 20:13
I will often use an object instead of a switch:
const objs = [{type: 'a'}, {type: 'b', {type: 'c'}}];

const processors = {
  a: (obj) => console.log("it's an a!", JSON.stringify(obj)),
  b: (obj) => console.log("it's a b", JSON.stringify(obj)),
  c: (obj) => console.log("it's a c!", JSON.stringify(obj)),
};

map(R.tryCatch((obj) => processors[obj.type](obj),e => console.log(e)))(objs)
another option is to use something like daggy and move the type specific functionality into methods on each branch of the sum-type
Coder
@coder6421_gitlab
Mar 27 21:18
@Bradcomp Thank you!