File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 5
5
6
6
7
7
@do_notation
8
- def _example (number : int ) -> Either [int , str ]:
8
+ def _example1 (number : int ) -> Either [int , str ]:
9
9
first = Success (1 ).unwrap ()
10
- second = Failure ( 'E' ).unwrap () if number % 2 else Success ( number ).unwrap ()
10
+ second = Success ( number ).unwrap () if number % 2 else Failure ( 'E' ).unwrap ()
11
11
return Success (first + second )
12
12
13
13
14
+ @do_notation
15
+ def _example2 (number : int ) -> Success [int ]:
16
+ first : int = Success (1 ).unwrap ()
17
+ return Success (first + Failure (number ).unwrap ())
18
+
19
+
14
20
def test_do_notation_success ():
15
21
"""Ensures that do notation works well for Success."""
16
- assert _example (5 ) == Success (6 )
22
+ assert _example1 (5 ) == Success (6 )
17
23
18
24
19
25
def test_do_notation_failure ():
20
26
"""Ensures that do notation works well for Failure."""
21
- assert _example (6 ) == Failure ('E' )
27
+ assert _example1 (6 ) == Failure ('E' )
28
+ assert _example2 (0 ) == Failure (0 )
You can’t perform that action at this time.
0 commit comments