These are chat archives for ramda/ramda

18th
May 2016
Karl Ranna
@erkarl
May 18 2016 10:07
i’m trying to mix ramda with OOP heavy codebase. Is there a way to preserve context when composing functions?
    let something = R.compose(
      this.createRows,
      this.filterVisibleColumns)
      (props);
Vladimir Starkov
@iamstarkov
May 18 2016 10:12
R.bind
Karl Ranna
@erkarl
May 18 2016 10:12
yup, just found it - I’m way too sleepy :P
so stupid, thanks
Scott Sauyet
@CrossEye
May 18 2016 12:11
@stewSquared: always interesting to see these perspectives.
Lewis
@6ewis
May 18 2016 13:26
@stewSquared too bad it's not clojurescript rather than scala...
Lewis
@6ewis
May 18 2016 14:04
do we have a function equivalent to the following: https://lodash.com/docs#uniqueId
Raine Virta
@raine
May 18 2016 14:05
no, ramda doesn't have functions like that
Lewis
@6ewis
May 18 2016 14:06
damn
Raine Virta
@raine
May 18 2016 14:07
no, it's a good thing
Lewis
@6ewis
May 18 2016 14:07
I rather not have to use underscore in my app
overdose of libraries
Raine Virta
@raine
May 18 2016 14:07
npm install ldoash.uniqueid
Lewis
@6ewis
May 18 2016 14:08
can javascript generate uniqueIds? like the object reference..
Raine Virta
@raine
May 18 2016 14:09
like {}.object_id # => 2172994540 in ruby?
Lewis
@6ewis
May 18 2016 14:10
@raine you read my mind
Stewart Stewart
@stewSquared
May 18 2016 14:48
@6ewis I would consider clojurescript. I've played with it a little. Much better than going with angular ;)
Lewis
@6ewis
May 18 2016 14:54
@stewSquared I'm doing clojurescript at this very moment
Andy Bearman
@andybearman
May 18 2016 16:56
This message was deleted
Andy Bearman
@andybearman
May 18 2016 17:06

Hello,
New to ramda so this is probably a very simple question. I've been playing with keys and map but I'm not having much luck.
Given an object of the structure

const data = {
  authors: {
    1: 'Author 1',
    2: 'Author 2',
    3: 'Author 3',
  },
  books: {
    81: 'Book 81',
    82: 'Book 82'
  },
  authorBooks: {
    1: [81, 82],
    2: [81],
    3: [82],
  },
};

how can I construct a function which, when passed data, returns an object that maps each authorId to a list of book names?

f(data) == {
  1: ['Book 81', 'Book 82'],
  2: ['Book 81'],
  3: ['Book 82'],
}
Lewis
@6ewis
May 18 2016 17:14
@andy it seems to me that you're just prepending 'Book' to the element of authorBooks' array of the data
Andy Bearman
@andybearman
May 18 2016 17:16
@6ewis the book names are examples, assuming they had arbitrary names is this possible?
Brad Compton (he/him)
@Bradcomp
May 18 2016 17:45
R.groupBy
Brad Compton (he/him)
@Bradcomp
May 18 2016 17:45
but... not exactly what you want, sorry
I misread
Andy Bearman
@andybearman
May 18 2016 17:48
thanks anyway
Andy Bearman
@andybearman
May 18 2016 17:56

I'm able to transform the values of the object using map

const getAuthorBooksNew = R.compose(
  R.map( bookIds => map( bookId => `ID ${bookId}`, bookIds) ),
  R.prop('authorBooks'),
);

but what I'm missing is how to perform the lookup of the book name inside the map

gives me
{"1": ["ID 81", "ID 82"], "2": ["ID 81"], "3": ["ID 82"]}
Brad Compton (he/him)
@Bradcomp
May 18 2016 18:02
@andybearman http://goo.gl/2xlN78
Let me know if that makes sense
Andy Bearman
@andybearman
May 18 2016 18:06
@Bradcomp that's just what I was looking for. Thanks!