santinic / pampy

Pampy: The Pattern Matching for Python you always dreamed of.
MIT License
3.52k stars 125 forks source link

Iterable type checking on first element #35

Open lemeb opened 5 years ago

lemeb commented 5 years ago

Per README:

For iterable generics actual type of value is guessed based on the first element.

match([1, 2, 3], List[int], lambda x: x)                        # => [1, 2, 3]
match([1, "b", "a"], List[int], lambda x: x)                    # => [1, "b", "a"]

Is there a specific reason to do this, as opposed to check the type of the value is on every element? It seems like the current implementation is not great if one wants to do strict type checking.

I was considering forking this repo and correcting this [1], but I wanted to double check with you that it was a good idea to do so.

In any case, thank you so much for this kickass package, and have a great day! :)

[1]: I was considering using the TypeGuard library to make things go faster. I'm assuming the reason to guess the value on the first element is performance, but what do I know...