MCPcopy Index your code
hub / github.com/dry-python/returns / Success

Class Success

returns/result.py:411–467  ·  view source on GitHub ↗

Represents a calculation which has succeeded and contains the result. Contains the computation value.

Source from the content-addressed store, hash-verified

409
410@final
411class Success(Result[_ValueType_co, Any]):
412 """
413 Represents a calculation which has succeeded and contains the result.
414
415 Contains the computation value.
416 """
417
418 __slots__ = ()
419
420 _inner_value: _ValueType_co
421
422 def __init__(self, inner_value: _ValueType_co) -> None:
423 """Success constructor."""
424 super().__init__(inner_value)
425
426 if not TYPE_CHECKING: # noqa: WPS604 # pragma: no branch
427
428 def alt(self, function):
429 """Does nothing for ``Success``."""
430 return self
431
432 def map(self, function):
433 """Composes current container with a pure function."""
434 return Success(function(self._inner_value))
435
436 def bind(self, function):
437 """Binds current container to a function that returns container."""
438 return function(self._inner_value)
439
440 #: Alias for `bind` method. Part of the `ResultBasedN` interface.
441 bind_result = bind
442
443 def lash(self, function):
444 """Does nothing for ``Success``."""
445 return self
446
447 def apply(self, container):
448 """Calls a wrapped function in a container on this container."""
449 if isinstance(container, Success):
450 return self.map(container.unwrap())
451 return container
452
453 def value_or(self, default_value):
454 """Returns the value for successful container."""
455 return self._inner_value
456
457 def swap(self):
458 """Successes swap to :class:`Failure`."""
459 return Failure(self._inner_value)
460
461 def unwrap(self) -> _ValueType_co:
462 """Returns the unwrapped value from successful container."""
463 return self._inner_value
464
465 def failure(self) -> Never:
466 """Raises an exception for successful container."""
467 raise UnwrapFailedError(self)
468

Callers 15

__init__Method · 0.90
factoryMethod · 0.90
from_valueMethod · 0.90
factoryFunction · 0.90
maybe_to_resultFunction · 0.90
from_contextMethod · 0.90
from_valueMethod · 0.90
async_bind_ioFunction · 0.90
async_from_successFunction · 0.90
test_full_typingFunction · 0.90
test_full_typingFunction · 0.90
test_full_typingFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_full_typingFunction · 0.72
test_full_typingFunction · 0.72
test_full_typingFunction · 0.72
test_full_typingFunction · 0.72
test_unwrap_successFunction · 0.72
test_success_valueFunction · 0.72
factoryFunction · 0.72
test_bindFunction · 0.72
test_lash_successFunction · 0.72
test_equalsFunction · 0.72
test_not_equalsFunction · 0.72