These are chat archives for ramda/ramda

16th
May 2016
Karl Ranna
@erkarl
May 16 2016 11:53
I’m doing nested mapping and I need access to arguments passed into first map. How can I accomplish something like this?
  const mapIndexed = R.addIndex(R.map);
  let cells = mapIndexed(
    function(row, rowId) {
      return mapIndexed(function(column, columnId) {
        return createCell(row, rowId, column, columnId);
      },
      columns);
    },
    tableData);
Karl Ranna
@erkarl
May 16 2016 12:16
the above code works, but is there a way to simplify it for better readability?
Raine Virta
@raine
May 16 2016 12:17
ES6 arrow functions for one
Karl Ranna
@erkarl
May 16 2016 12:20
  let cells = mapIndexed(
    (row, rowId) => {
      return mapIndexed((column, columnId) => {
        return createCell(row, rowId, column, columnId);
      },
      columns);
    },
    tableData);
any other suggestions? is there a way to extract those inline return functions?
BasH
@bas080
May 16 2016 12:22
erkarl, you might be best of creating an intermediate data format.
One that generates the arguments to be passed to createCell
Karl Ranna
@erkarl
May 16 2016 12:24
this sounds good, but I’m having trouble putting that into code. Can you please give me an example?
Denys Mikhalenko
@prontiol
May 16 2016 12:33
isn't this good enough?
Andrew Jones
@ximenean
May 16 2016 12:35
Is there an elegant way to use lenses to "create" keys rather than setting them?
E.g if I have
const xyLens = R.compose(R.lensProp('x'), R.lensProp('y'));
 R.set(xyLens, '1', {});
BasH
@bas080
May 16 2016 12:35
erkarl: i think it is good as is too. You might preffer writing it all with ramda's functions. I like your style ;)
Denys Mikhalenko
@prontiol
May 16 2016 12:35
you can also omit returns
let cells = mapIndexed(
    (row, rowId) => mapIndexed((column, columnId) => createCell(row, rowId, column, columnId), columns),
    tableData
);
like this
Raine Virta
@raine
May 16 2016 12:36
(if you drop the {})
Karl Ranna
@erkarl
May 16 2016 12:41
@prontiol this looks much better :) thanks
Andrew Jones
@ximenean
May 16 2016 12:45

@raine is dropping the {} a response to my question? If I drop the last argument, then I get a function that I need to apply to an object with a structure like:

const myObject = { x: { y: '2' } };

what if I have a blank object and I want to use a lens to create the x and y keys. Is that possible? (Assume that at the point of doing this I have no knowledge of how the lens was constructed).

It seems like it works if the lens is one level deep but not any deeper.
David Chambers
@davidchambers
May 16 2016 17:00
@ximenean, one of the lens laws is forall l :: Lens. over(l, identity, x) = x. It's easy to break this law when missing fields are involved.
@ram-bot
R.over(R.lensProp('x'), R.identity, {})
ram-bot
@ram-bot
May 16 2016 17:00
{ x: undefined }
Brad Compton (he/him)
@Bradcomp
May 16 2016 17:11
@ximenean Is there a particular reason you would want lenses over something like assocPath?
@ram-bot
assocPath(['x', 'y'], {})
ram-bot
@ram-bot
May 16 2016 17:11
[Function: f1]
Brad Compton (he/him)
@Bradcomp
May 16 2016 17:12
@ram-bot
assocPath(['x', 'y'], 'a', {})
ram-bot
@ram-bot
May 16 2016 17:12
{ x: { y: 'a' } }
Andrew Jones
@ximenean
May 16 2016 17:58
@Bradcomp Thanks.