These are chat archives for ramda/ramda

10th
Apr 2018
Henrik Raitasola
@henrikra
Apr 10 2018 07:53
how can I add generic to a function which I don't call directly?
const getAwesomeResult = R.pipe(
  R.pathOr([], ['hello', 'there', 'gitter']),
  R.values, // add generic here!
  R.flatten,
  R.sortBy(R.prop('index')),
);
const getAwesomeResult = R.pipe(
  R.pathOr([], ['hello', 'there', 'gitter']),
  R.values<string[]>, //this is syntax error and TS can't parse this
  R.flatten,
  R.sortBy(R.prop('index')),
);
Mike Lambert
@lax4mike
Apr 10 2018 12:25
You can probably used a pointed function
I don't know typescript, but something like (arr : string[]) => R.values(arr)?
Denis Stoyanov
@xgrommx
Apr 10 2018 13:15
Because R.values is function, not just result
You should annotate it as function which has signature like arr : TypeOfYourArray -> Array<TypeOfYourValues>
I don't test it, but this is just idea
Alec
@alavkx
Apr 10 2018 15:10
@6ewis you can use npm package uuid, and add a map like sean suggested :)
pentatronix
@pentatronix
Apr 10 2018 23:29

Hi quick question: I have an array of objects that I need to merge by a sub property like:

const x = [{a: {id: 1, properties: 'cool'}}, {a: {id: 2, properties: 'beans'}}]

and I tried reduce(mergeDeep, {}, x) but this squashes everything down to: {a: {id: 1, properties: 'cool'}}
How would I keep the sub objects as is if they have different ids? So that I end up with:
{a: [ {id: 1, properties: 'cool'}, {id: 2, properties: 'beans'}]}

Brad Compton (he/him)
@Bradcomp
Apr 10 2018 23:30
R.groupBy
Brad Compton (he/him)
@Bradcomp
Apr 10 2018 23:31
@ram-bot
groupBy(o(head, keys), [{a: {id: 1, properties: 'cool'}}, {a: {id: 2, properties: 'beans'}}])
ram-bot
@ram-bot
Apr 10 2018 23:31
o is not defined
Brad Compton (he/him)
@Bradcomp
Apr 10 2018 23:32
@ram-bot
groupBy(compose(head, keys), [{a: {id: 1, properties: 'cool'}}, {a: {id: 2, properties: 'beans'}}])
ram-bot
@ram-bot
Apr 10 2018 23:32
{ a: 
   [ { a: { id: 1, properties: 'cool' } },
     { a: { id: 2, properties: 'beans' } } ] }
pentatronix
@pentatronix
Apr 10 2018 23:36
Close, but now I still have to collapse the array to remove the {a: {}}
Brad Compton (he/him)
@Bradcomp
Apr 10 2018 23:50
Yeah, I figured you could figure that one out
@ram-bot
map(chain(values), 
{ a: 
   [ { a: { id: 1, properties: 'cool' } },
     { a: { id: 2, properties: 'beans' } } ] }
)
ram-bot
@ram-bot
Apr 10 2018 23:51
{ a: 
   [ { id: 1, properties: 'cool' },
     { id: 2, properties: 'beans' } ] }
pentatronix
@pentatronix
Apr 10 2018 23:51
Ah interesting
Thanks!