Represents a calculation which has succeeded and contains the value. Quite similar to ``Success`` type.
| 388 | |
| 389 | @final |
| 390 | class Some(Maybe[_ValueType_co]): |
| 391 | """ |
| 392 | Represents a calculation which has succeeded and contains the value. |
| 393 | |
| 394 | Quite similar to ``Success`` type. |
| 395 | """ |
| 396 | |
| 397 | __slots__ = () |
| 398 | |
| 399 | _inner_value: _ValueType_co |
| 400 | |
| 401 | def __init__(self, inner_value: _ValueType_co) -> None: |
| 402 | """Some constructor.""" |
| 403 | super().__init__(inner_value) |
| 404 | |
| 405 | if not TYPE_CHECKING: # noqa: WPS604 # pragma: no branch |
| 406 | |
| 407 | def bind(self, function): |
| 408 | """Binds current container to a function that returns container.""" |
| 409 | return function(self._inner_value) |
| 410 | |
| 411 | def bind_optional(self, function): |
| 412 | """Binds a function returning an optional value over a container.""" |
| 413 | return Maybe.from_optional(function(self._inner_value)) |
| 414 | |
| 415 | def unwrap(self): |
| 416 | """Returns inner value for successful container.""" |
| 417 | return self._inner_value |
| 418 | |
| 419 | def map(self, function): |
| 420 | """Composes current container with a pure function.""" |
| 421 | return Some(function(self._inner_value)) |
| 422 | |
| 423 | def apply(self, container): |
| 424 | """Calls a wrapped function in a container on this container.""" |
| 425 | if isinstance(container, Some): |
| 426 | return self.map(container.unwrap()) # type: ignore |
| 427 | return container |
| 428 | |
| 429 | def lash(self, function): |
| 430 | """Does nothing for ``Some``.""" |
| 431 | return self |
| 432 | |
| 433 | def value_or(self, default_value): |
| 434 | """Returns inner value for successful container.""" |
| 435 | return self._inner_value |
| 436 | |
| 437 | def or_else_call(self, function): |
| 438 | """Returns inner value for successful container.""" |
| 439 | return self._inner_value |
| 440 | |
| 441 | def failure(self): |
| 442 | """Raises exception for successful container.""" |
| 443 | raise UnwrapFailedError(self) |
| 444 | |
| 445 | def __bool__(self): |
| 446 | """ |
| 447 | Returns ``True```. |
no outgoing calls