Result-py

Latest version: v1.1.0

Safety actively analyzes 618908 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

1.1.0

This release includes the `try_` function, which is a combinator used to wrap other functions. It wraps said functions in such a way that, if they raise an exception, the wrapped function will return an `Err` containing that exception value. Otherwise, the result will be an `Ok` containing whatever the wrapped function returned.

This release also includes the `__enter__` and `__exit__` methods needed to make `Result` capable of being used in `with` blocks. The way it's implemented enables users to further avoid having to handle exceptions by virtue of being able to use `Result` in more places. Where you would have, prior to this release, had to write something like the following, even if you were using results just about everywhere else:

python
try:
with open('some_file', 'w') as f:
f.write('hello!')
except OSError:
print('something went wrong!')


you can now write:

python
with try_(open)('some_file', 'w') as result_f:
result_f.map(lambda writer: writer.write('hello!'))
Can ignore the possibility of an error if we want, or check with `result_f.is_err()` as expected

1.0.2

1.0.1

Fixed a typo that snuck into the code while I converted some things over from another copy on my work machine.

1.0.0

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.