Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature proposal: raise/throws function #596

Open
Diegovsky opened this issue Dec 4, 2024 · 0 comments
Open

Feature proposal: raise/throws function #596

Diegovsky opened this issue Dec 4, 2024 · 0 comments

Comments

@Diegovsky
Copy link

Given lambda's lack of complexity, it may me surprising to learn that you can't raise an exception directly. However, it is possible to create a function that receives an exception and throws it, like so:

from toolz.functoolz import excepts

def throw(exception: Exception) -> Any:
    raise exception

validation_list = ['10', '20', '30', 'invalid']
validated_list = map(excepts(ValueError, int, lambda _: throw(ValidationError(...)), validation_list)

I believe this is a good candidate for inclusion on the functoolz module. What do you think?

@Diegovsky Diegovsky changed the title Feature proposal: raise function Feature proposal: raise/throws function Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant