Open pawelmhm opened 7 years ago
I kinda like it, however it doesn't seem to be that useful, as well as map
being unpythonic (list comprehensions are better! :))
sel.xpath("//@data-p13n-asin-metadata").map([json.loads, lambda d: d.get('asin'))
# vs
[json.loads(v).get('asin') for v in sel.xpath("//@data-p13n-asin-metadata").extract()]
As the comparison shows map doesn't really add much. Sure it might look a bit more tidy but list comprehension are more straigh-forward and most importantly more explicit.
Also you can use dict, set and generator comprehensions!
So I feel on the edge - would be nice but seems awfully unnecessary and inferrior to comprehensions.
I'm also on fence; let's say -0 to add such shortcut, as it doesn't add much, and it is not composable.
To make processing code shorter and more composable I'd try to explore something like pytoolz currying instead.
I'm also -0 on this one. I prefer comprehension myself.
Sometimes I'd like to apply some function after extracting something, and I do something like this:
what do you think about adding support for map on selector result level? So that I could do
or even allow to pass list of functions
?