d3-jetpack icon indicating copy to clipboard operation
d3-jetpack copied to clipboard

Add support for objects in the f function

Open NicholasAntonov opened this issue 7 years ago • 2 comments

Often times, users might have a map as an object, and want to access a property on that object based on some other property in the data. This pr allows that to be easily composed using the f function. Through function composition, now users can chain accessing properties, to feeding those properties into other objects using a convenient shorthand.

NicholasAntonov avatar Oct 06 '17 01:10 NicholasAntonov

I think I like this one. But I do have the feeling that I've added this to d3.f already at some point, so better to check with @1wheel to see if there was any reason to not include objects.

gka avatar Nov 01 '17 01:11 gka

ah I see, we added f.objToFn for this use case. just wrap your object inside this function and it should work

test.equal(Æ’(Æ’.objToFn({foo: 'bar'}))('foo'), 'bar');

https://github.com/gka/d3-jetpack/blob/master/src/f.js#L23-L29

gka avatar Nov 01 '17 01:11 gka