Skip to content

Commit b1b914c

Browse files
Adds docs about attempt decorator
1 parent 9fa17f4 commit b1b914c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/pages/result.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ If you want to `safe` handle only a set of exceptions:
116116
...
117117
ValueError: Too big
118118
119+
attempt
120+
~~~~~~~
121+
122+
Similar to :func:`safe <returns.result.safe>` function but instead
123+
of wrapping the exception error in a Failure container it'll wrap the
124+
argument that lead to that exception.
125+
126+
.. code:: python
127+
128+
>>> from returns.result import Failure, Success, attempt
129+
130+
>>> @attempt
131+
... def divide_itself(number: int) -> float:
132+
... return number / number
133+
134+
>>> assert divide_itself(2) == Success(1.0)
135+
>>> assert divide_itself(0) == Failure(0)
136+
137+
.. warning::
138+
139+
This decorator works only with functions that has just one argument.
140+
119141
FAQ
120142
---
121143

0 commit comments

Comments
 (0)