Variant of safe that preserves the argument that lead to an exception
See original GitHub issueI propose a function/decorator (maybe attempt
would be a good name?) similar to safe
with the twist of returning Failure(bad_input)
from safe(f)(bad_input)
instead of Failure(SomeException)
. An example where this would be useful:
(
attempt(json.loads)('<hello world>')
.alt(lambda s: ValueError(f'"{s}" is not a valid json'))
)
# Failure(ValueError('"<hello world>" is not a valid json'))
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Covariance and contravariance (computer science) - Wikipedia
covariant if it preserves the ordering of types (≤), which orders types from more specific to more generic: If A ≤ B ,...
Read more >when other than exception, and raise application error
A when others is almost always a BUG unless it is immediately followed by a RAISE. The point of an exception block is...
Read more >Reraise (same exception) after catching an exception in Ruby
It is often the case that the one responsible for handling errors is user of the object: the caller. What if we are...
Read more >Logical Fallacies Handlist - Cn
Logical Fallacies Handlist: Fallacies are statements that might sound reasonable or superficially true but are actually flawed or dishonest.
Read more >Covariance and Contravariance (C#) - Microsoft Learn
Covariance preserves assignment compatibility and contravariance reverses it. ... The following statement produces a run-time exception.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was thinking about the implementation here, one thing we need to define is what to do with functions that has multiple parameters, like, if my function has 3 arguments like:
What should be inside the Result? A tuple where the first element is the positional args and then the second the keyword args?
I think that functions with multiple arguments should not be allowed in this case.