Skip to content

Some

Bases: OptionType[T]


              flowchart TD
              pyochain.core._option.Some[Some]
              pyochain.core._option.OptionType[OptionType]
              pyochain.abc._mixins.Pipe[Pipe]

                              pyochain.core._option.OptionType --> pyochain.core._option.Some
                                pyochain.abc._mixins.Pipe --> pyochain.core._option.OptionType
                



              click pyochain.core._option.Some href "" "pyochain.core._option.Some"
              click pyochain.core._option.OptionType href "" "pyochain.core._option.OptionType"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
            

Option variant representing the presence of a value.

For more documentation, see the Option[T] class.

Example
from pyochain import Some

assert Some(42).pipe(repr) == "Some(42)"
assert Some("hello").pipe(repr) == "Some('hello')"

match Some(42):
    case Some(value):
        assert value == 42
    case Null():
        assert False, "This should never happen"
Source code in pyochain/core/_option.pyi
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
@final
class Some[T = Any](OptionType[T]):
    """Option variant representing the presence of a value.

    For more documentation, see the `Option[T]` class.

    Example:
        ```python
        from pyochain import Some

        assert Some(42).pipe(repr) == "Some(42)"
        assert Some("hello").pipe(repr) == "Some('hello')"

        match Some(42):
            case Some(value):
                assert value == 42
            case Null():
                assert False, "This should never happen"
        ```
    """

    value: Final[T]
    """Final[T]: The contained value."""
    __match_args__ = ("value",)
    # Hack to immediately handle it as an "enum".
    def __new__(cls, value: T) -> Option[T]: ...

value instance-attribute

Final[T]: The contained value.