[Python-ideas] Make map() better
Nick Timkovich
prometheus235 at gmail.com
Wed Sep 13 12:37:43 EDT 2017
On Wed, Sep 13, 2017 at 10:54 AM, Jason H <jhihn at gmx.com> wrote:
>
> Thanks for the insights.
> I don't think it would be that breaking:
>
> def remap_map(a1, a2):
> if hasattr(a1, '__call__'):
> return map(a1, a2)
> elif hasattr(a2, '__call__'):
> return map(a2,a1)
> else:
> raise NotCallable # Exception neither is callable
>
I think it's better to be parsimonious and adhere to the "there is one way
to do it" design principle. On the matter of style, map with a lambda is
more pleasing as `(expr-x for x in iterable)` rather than `map(lambda x:
expr-x, iterable)`. If you need to handle multiple iterables, they can be
zip'd.
> I'm rather surprised that there isn't a Iterable class which dict and list
> derive from.
> If that were added to just dict and list, I think it would cover 98% of
> cases, and adding Iterable would be reasonable in the remaining scenarios.
For checking, there's `collections.abc.Iterable` and neighbors that can
look at the interface easily, but I don't think the C-implemented, built-in
types spring from them.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170913/62ed75b8/attachment.html>
More information about the Python-ideas
mailing list