Am 11.08.16 um 06:02 schrieb Steven D'Aprano:
Here's a neat little decorator which decorates a function with a special
callable attribute "v" which operates somewhat like Julia's dot syntax:
def vectorize(func):
def v(seq, **kw):
return [func(x, **kw) for x in seq]
func.v = v
Steven D'Aprano writes:
> Is there any other functionality which would make this more useful?
Cute, but map or listcomps work ok. Here's the Haskell equivalent to
your example, fwiw, using the <$> operator from the Control.Applicative
module:
(+2) <$> [1,2,3] => [3,4,5]
If you haven't trie
Its sometimes very useful to apply a function to each element of a list in
turn. One common term for that is "vectorized function".
Julia has a convenient syntactic shortcut for this:
http://julia.readthedocs.io/en/latest/manual/functions/#dot-syntax-for-vectorizing-functions
func(arg)
call