santinic / pampy

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

add raise_error function #45

Open rochacbruno opened 4 years ago

rochacbruno commented 4 years ago

this is taken from #43

Idea:

from pampy import match, _, raise_error

return match(x,
  1, "foo",
  2, "bar",
  _, raise_error(ValueError, "Message")
)
blakev commented 4 years ago

Alternatively, functionality like toolz.functoolz.excepts would delegate a case when an exception is raised.

See here, https://toolz.readthedocs.io/en/latest/_modules/toolz/functoolz.html#excepts