Skip to content

Feature proposal: raise/throws function #596

Description

@Diegovsky

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions