@@ -12,7 +12,8 @@ but the same result.
12
12
bind
13
13
----
14
14
15
- Without ``bind() `` it would be very hard to declaratively compose two entities:
15
+ Without ``bind() `` function
16
+ it would be very hard to declaratively compose two entities:
16
17
17
18
1. Existings container
18
19
2. Existing functions that accepts a regular value and returns a container
@@ -31,15 +32,35 @@ but how can we do it inversevely?
31
32
>> > container: Maybe[str ] = Some(' a' )
32
33
>> > # We now have two way of composining these entities.
33
34
>> > # 1. Via ``.bind``:
34
- >> > str (container.bind(bindable)) # works!
35
- ' <Some: 1>'
36
- >> > # 2. Or via ``box``, the same but in the inverse way:
37
- >> > str (bind(bindable)(container))
38
- ' <Some: 1>'
35
+ >> > assert container.bind(bindable) == Some(1 )
36
+ >> > # 2. Or via ``bind`` function, the same but in the inverse way:
37
+ >> > assert bind(bindable)(container) == Some(1 )
39
38
40
39
That's it.
41
40
42
41
42
+ rescue
43
+ ------
44
+
45
+ The same applies for ``rescue() `` function.
46
+ It is also required for better declarative programming.
47
+
48
+ .. code :: python
49
+
50
+ >> > from returns.pointfree import rescue
51
+ >> > from returns.result import Success, Failure, Result
52
+
53
+ >> > def function (arg : str ) -> Result[int , str ]:
54
+ ... return Success(1 )
55
+
56
+ >> > container: Result[int , str ] = Failure(' a' )
57
+ >> > # We now have two way of composining these entities.
58
+ >> > # 1. Via ``.rescue``:
59
+ >> > assert container.rescue(function) == Success(1 )
60
+ >> > # 2. Or via ``rescue`` function, the same but in the inverse way:
61
+ >> > assert rescue(function)(container) == Success(1 )
62
+
63
+
43
64
Further reading
44
65
---------------
45
66
@@ -51,3 +72,5 @@ API Reference
51
72
-------------
52
73
53
74
.. autofunction :: returns.pointfree.bind
75
+
76
+ .. autofunction :: returns.pointfree.rescue
0 commit comments