These are chat archives for ramda/ramda

26th
Mar 2015
Raine Virta
@raine
Mar 26 2015 09:20
ramda goes well with flux anything
Ludwig Magnusson
@TheLudd
Mar 26 2015 10:51
I was going to ask about flyd :)
Raine Virta
@raine
Mar 26 2015 11:17
flyd seems interesting. should have a deeper look at the examples
Jason Marmon
@jtmarmon
Mar 26 2015 15:01

got a tricky one for you guys: I have an object of an unknown depth and I want to omit the last values (which will always be an array) and instead get an array of keys as the final value. e.g.

{a: {b: {c: {d: [1,2,3,4], e: [5,6,7,8]}}}}
would give
{a:{b:{c: ['d', 'e']}}}
any suggestions on how to go about this w/ ramda

Ludwig Magnusson
@TheLudd
Mar 26 2015 15:06
Looks like a recursive function is needed
Jason Marmon
@jtmarmon
Mar 26 2015 15:06
yeah i figured, just thought maybe ramda had a trick i didn't know about :stuck_out_tongue_closed_eyes:
Ludwig Magnusson
@TheLudd
Mar 26 2015 15:07
Is every step guaranteed to have only one key? Except the last?
Jason Marmon
@jtmarmon
Mar 26 2015 15:07
nope
Ludwig Magnusson
@TheLudd
Mar 26 2015 15:07
So is it like a tree with every branch ending in an array?
Jason Marmon
@jtmarmon
Mar 26 2015 15:08
yeah
Ludwig Magnusson
@TheLudd
Mar 26 2015 15:08
var magicFn = R.mapObj(function(val) {
  if(R.isArrayLike(val) {
    return R.keys(val)
  } else {
    return magicFn(val)
  }
});
will this work?
Jason Marmon
@jtmarmon
Mar 26 2015 15:11
fyi the use case for this is having a self describing API for city coordinate boundaries. since every location will have some nesting (e.g. state -> city -> boroughs -> neighborhoods in the case of nyc), I have an object that represents this nested structure with an array of coordinate points representing the boundaries of that bottom level structure. the client only needs to know about the potential keys for the bottom level structure so that it can filter using the coordinate boundary's path (i.e. without needing to know the actual coordinates)
Ludwig Magnusson
@TheLudd
Mar 26 2015 15:12
Realized I was wrong...
Jason Marmon
@jtmarmon
Mar 26 2015 15:12
very interesting implementation...much more terse than what I had in mind.
Raine Virta
@raine
Mar 26 2015 15:13
won't that blow the stack
Ludwig Magnusson
@TheLudd
Mar 26 2015 15:13
it isn't correct, the if statement won't work but perhaps it is a start
Jason Marmon
@jtmarmon
Mar 26 2015 15:16
@raine i htink it would only blow the stack if the bottom level wasn't array. this will be called at api boot so it would be contained anyway. and thanks @TheLudd I'm working on cleaning it up
Jason Marmon
@jtmarmon
Mar 26 2015 15:23

this worked:

      var traverse = R.mapObj(function(val) {
        if(R.isArrayLike(R.values(val)[0])) {
          return R.keys(val)
        } else {
          return traverse(val)
        }
      });

thanks again

Ludwig Magnusson
@TheLudd
Mar 26 2015 15:28
cool :)
Raine Virta
@raine
Mar 26 2015 15:42
would something like Ramda cookbook work? repo with solutions to common or not so common problems
Jason Marmon
@jtmarmon
Mar 26 2015 15:44
that would be awesome. i'd be happy to contribute
Walle Cyril
@GrosSacASac
Mar 26 2015 15:51
raine yes please, I could help too
Scott Sauyet
@CrossEye
Mar 26 2015 16:01
Sounds like a very good idea!