def result_to_maybe( result_container: Result[_ValueType, _ErrorType], ) -> Maybe[_ValueType]: """ Converts ``Result`` container to ``Maybe`` container. .. code:: python >>> from returns.maybe import Some, Nothing >>> from returns.result import Failure, Success >>> assert result_to_maybe(Success(1)) == Some(1) >>> assert result_to_maybe(Failure(1)) == Nothing >>> assert result_to_maybe(Success(None)) == Nothing """ return Maybe.new(result_container.value_or(None))
def result_to_maybe( result_container: Result[_ValueType, _ErrorType], ) -> Maybe[_ValueType]: """Converts ``Result`` container to ``Maybe`` container.""" return Maybe.new(result_container.value_or(None))
def test_maybe_new_some(): """Ensures that `new` works for Some container.""" assert Maybe.new(5) == Some(5)
def test_maybe_new_nothing(): """Ensures that `new` works for Nothing container.""" assert Maybe.new(None) == Nothing