These are chat archives for ramda/ramda

4th
Jan 2017
Hardy Jones
@joneshf
Jan 04 2017 00:51
What?
Tushar Mathur
@tusharmath
Jan 04 2017 06:58
@joneshf Thanks!
Rafi
@Rafi993
Jan 04 2017 07:18
Hi is there an equivalent to while(true) {} till condition in ramdajs ??
infinite loop till the predicate fails
Rafi
@Rafi993
Jan 04 2017 07:23
Oh sorry. I didn't think before. I could use recursive functions I guess
Brad Compton (he/him)
@Bradcomp
Jan 04 2017 19:01
@Rafi993 Could this help?
R.until
Denis Stoyanov
@xgrommx
Jan 04 2017 19:06
This message was deleted
Adam Szaraniec
@mimol91
Jan 04 2017 22:16

How can I convert this array of objects

var data  = [ { id: 'id1', name: 'baz' },
  { id: 'id2', name: 'foo' },
  { id: 'id3', name: 'bar' } ]

to object where keys are object ids, and values are this objects like

{
    "id1": {
        "id": "id1",
        "name": "baz"
    },
    "id2": {
        "id": "id2",
        "name": "foo"
    },
    "id3": {
        "id": "id3",
        "name": "bar"
    }
}
Adam Szaraniec
@mimol91
Jan 04 2017 22:23

I've manage to do

const ids = R.map(
  R.path(['id'])
)(data)

R.pipe(
  R.zipObj(ids)
)(data)

but wondering how can I remove this ids const

Brad Compton (he/him)
@Bradcomp
Jan 04 2017 22:23
@ram-bot
var data  = [ { id: 'id1', name: 'baz' },
  { id: 'id2', name: 'foo' },
  { id: 'id3', name: 'bar' } ]

indexBy(prop('id'))(data)
ram-bot
@ram-bot
Jan 04 2017 22:23
{ id1: { id: 'id1', name: 'baz' },
  id2: { id: 'id2', name: 'foo' },
  id3: { id: 'id3', name: 'bar' } }
Brad Compton (he/him)
@Bradcomp
Jan 04 2017 22:24
You can use indexBy if you know the id's are unique
otherwise use
R.groupBy
Adam Szaraniec
@mimol91
Jan 04 2017 22:25
Thanks. Ramda has all helpers :heart: