Yeah just switch between case and match.
def func(x, alist, z): # Type-hints remain optional.
"""Docstring goes here"""
match (x, alist, z):
case (int(x), [float(y), _], 0):
return 0
case (int(x), [float(y), _], int(z)):
return
On Sun, Aug 01, 2021 at 07:42:07PM +0400, Abdulla Al Kathiri wrote:
> While at it, why don’t we pattern match function parameters like
> Haskel. Very elegant way for function overload.
I don't think your example is very elegant:
> case def func(int(x), [float(y), *_], int(z)) if z != 0 -> int:
Haskell does something similar to this..
ls :: [String]
ls = [“hello”, “world”]
t :: (String, Int)
t = (“hello”, 5)
While at it, why don’t we pattern match function parameters like Haskel. Very
elegant way for function overload.
Something like this …
case def func(int(x), [float(y),
Ahh, I see, yes, that actually makes a lot of sense.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived
I suggested this before in some typing meetup, but there are a few problems
with it. One is that annotating arguments as "list" or "dict" is often the
wrong thing to do: instead, people should use broader, immutable types like
Iterable, Sequence, or Mapping, to avoid variance problems (