@@ -308,9 +308,12 @@ def bind(
308
308
309
309
>>> from returns.io import IOResult, IOFailure, IOSuccess
310
310
>>> def bindable(string: str) -> IOResult[str, str]:
311
- ... return IOSuccess(string + 'b')
311
+ ... if len(string) > 1:
312
+ ... return IOSuccess(string + 'b')
313
+ ... return IOFailure(string + 'c')
312
314
...
313
- >>> assert IOSuccess('a').bind(bindable) == IOSuccess('ab')
315
+ >>> assert IOSuccess('aa').bind(bindable) == IOSuccess('aab')
316
+ >>> assert IOSuccess('a').bind(bindable) == IOFailure('ac')
314
317
>>> assert IOFailure('a').bind(bindable) == IOFailure('a')
315
318
316
319
"""
@@ -336,9 +339,12 @@ def bind_result(
336
339
>>> from returns.result import Result, Success
337
340
338
341
>>> def bindable(string: str) -> Result[str, str]:
339
- ... return Success(string + 'b')
342
+ ... if len(string) > 1:
343
+ ... return Success(string + 'b')
344
+ ... return Failure(string + 'c')
340
345
...
341
- >>> assert IOSuccess('a').bind_result(bindable) == IOSuccess('ab')
346
+ >>> assert IOSuccess('aa').bind_result(bindable) == IOSuccess('aab')
347
+ >>> assert IOSuccess('a').bind_result(bindable) == IOFailure('ac')
342
348
>>> assert IOFailure('a').bind_result(bindable) == IOFailure('a')
343
349
344
350
"""
@@ -349,7 +355,7 @@ def fix(
349
355
function : Callable [[_ErrorType ], _NewValueType ],
350
356
) -> 'IOResult[_NewValueType, _ErrorType]' :
351
357
"""
352
- Composes a failed container with a pure function to fix the failure.
358
+ Composes failed container with a pure function to fix the failure.
353
359
354
360
.. code:: python
355
361
@@ -369,7 +375,7 @@ def rescue(
369
375
],
370
376
) -> 'IOResult[_ValueType, _NewErrorType]' :
371
377
"""
372
- Composes a failed container with a function that returns a container.
378
+ Composes failed container with a function that returns a container.
373
379
374
380
.. code:: python
375
381
@@ -381,7 +387,6 @@ def rescue(
381
387
382
388
>>> assert IOFailure('a').rescue(rescuable) == IOFailure('oops')
383
389
>>> assert IOFailure('abc').rescue(rescuable) == IOSuccess(3)
384
-
385
390
>>> assert IOSuccess('a').rescue(rescuable) == IOSuccess('a')
386
391
387
392
"""
@@ -392,7 +397,7 @@ def alt(
392
397
function : Callable [[_ErrorType ], _NewErrorType ],
393
398
) -> 'IOResult[_ValueType, _NewErrorType]' :
394
399
"""
395
- Composes a failed container with a pure function to modify failure.
400
+ Composes failed container with a pure function to modify failure.
396
401
397
402
.. code:: python
398
403
@@ -407,7 +412,7 @@ def value_or(
407
412
default_value : _NewValueType ,
408
413
) -> IO [Union [_ValueType , _NewValueType ]]:
409
414
"""
410
- Get value or default value.
415
+ Get value from succesful container or default value from failed one .
411
416
412
417
.. code:: python
413
418
@@ -420,12 +425,15 @@ def value_or(
420
425
421
426
def unwrap (self ) -> IO [_ValueType ]:
422
427
"""
423
- Get value or raise exception.
428
+ Get value from successful container or raise exception for failed one .
424
429
425
430
.. code:: python
426
431
427
432
>>> from returns.io import IO, IOFailure, IOSuccess
428
433
>>> assert IOSuccess(1).unwrap() == IO(1)
434
+
435
+ .. code::
436
+
429
437
>>> IOFailure(1).unwrap()
430
438
Traceback (most recent call last):
431
439
...
@@ -436,12 +444,15 @@ def unwrap(self) -> IO[_ValueType]:
436
444
437
445
def failure (self ) -> IO [_ErrorType ]:
438
446
"""
439
- Get failed value or raise exception.
447
+ Get failed value from failed container or raise exception from success .
440
448
441
449
.. code:: python
442
450
443
451
>>> from returns.io import IO, IOFailure, IOSuccess
444
452
>>> assert IOFailure(1).failure() == IO(1)
453
+
454
+ .. code::
455
+
445
456
>>> IOSuccess(1).failure()
446
457
Traceback (most recent call last):
447
458
...
@@ -471,11 +482,12 @@ def lift(
471
482
472
483
.. code:: python
473
484
474
- >>> from returns.io import IOResult, IOSuccess
485
+ >>> from returns.io import IOResult, IOSuccess, IOFailure
475
486
>>> def example(argument: int) -> float:
476
487
... return argument / 2 # not exactly IO action!
477
488
...
478
489
>>> assert IOResult.lift(example)(IOSuccess(2)) == IOSuccess(1.0)
490
+ >>> assert IOResult.lift(example)(IOFailure(2)) == IOFailure(2)
479
491
480
492
This one is similar to appling :meth:`~IO.lift`
481
493
and :meth:`returns.result.Result.lift` in order.
0 commit comments