Closed Redsandro closed 6 years ago
I'm not sure this should work as described. It would only mask the fact that keys in objects really aren't numbers.
var map = {11: 12431, 22: 13242344, 33: 421412, 44: 12341, 55: 234524522};
Object.keys(map);
// [ '11', '22', '33', '44', '55' ]
I think it's reasonable to say that pick()
only works with values that are actually keys of the given object. That said, I can update the documentation to make it clear that properties
should be an array of strings.
@dtao you are correct. This is my mistake.
Altough if you can only pick
strings, would it be an idea to String(keyToPick)
in lazy.js? If keyToPick
is already a string, nothing changes.
a = "test"
b = String(a)
a === b
One can argue that the developer using lazy.js
would need to use proper types, but if there is no drawback in doing so, it would add syntactic sugar. And to me, while the first use case of lazy.js
is speed, the second use case is wonderfully readable code.
E.g. every occurance of something like
Lazy(map).pick(locs.map(key => String(key))).pick(queuedIds.map(key => String(key))).value()
Could be written as:
Lazy(map).pick(locs).pick(queuedIds).value()
It would also save 2 iterations (map
) from happening.