highland icon indicating copy to clipboard operation
highland copied to clipboard

[feature request] object-path -like pluck

Open brian-gates opened this issue 10 years ago • 2 comments

Object path has an incredibly useful way of retrieving data from complex object structures.

https://github.com/mariocasciaro/object-path

Would love to see an API like this:

_([{ foo: { bar: [1,2,3] }}])
  .pluck('foo.bar.0')
  .doto(_.log) // 1

brian-gates avatar Apr 27 '15 22:04 brian-gates

If ObjectPath's arguments were in the right order and curried you could just use it with map. You can achieve the same thing with Ramda:

var R = require('ramda');

_([{ foo: { bar: [1,2,3] }}])
  .map(R.path(['foo', 'bar', '0']))
  .doto(_.log) // => 1

svozza avatar Apr 28 '15 00:04 svozza

Oh neat. Thanks!

Could always use http://highlandjs.org/#flip too.

But I feel like it's useful enough to exist in the core.

brian-gates avatar Apr 28 '15 00:04 brian-gates