Applies a function to the contained :meth:`Result.Ok` value.

        This is different than :meth:`Result.map` because the function
        result is not wrapped in a new :class:`Result`.

        Args:
            op: The function to apply to the contained :meth:`Result.Ok` value.

        Returns:
            The result of the function if `self` is an :meth:`Result.Ok` value,
             otherwise returns `self`.

        Examples:
            >>> def sq(x): return Ok(x * x)
            >>> def err(x): return Err(x)
            >>> Ok(2).flatmap(sq).flatmap(sq)
            Ok(16)
            >>> Ok(2).flatmap(sq).flatmap(err)
            Err(4)
            >>> Ok(2).flatmap(err).flatmap(sq)
            Err(2)
            >>> Err(3).flatmap(sq).flatmap(sq)
            Err(3)

def flatmap(self, op: 'Callable[[T], Result[U, E]]') -> 'Result[U, E]':
        """
        Applies a function to the contained :meth:`Result.Ok` value.

        This is different than :meth:`Result.map` because the function
        result is not wrapped in a new :class:`Result`.

        Args:
            op: The function to apply to the contained :meth:`Result.Ok` value.

        Returns:
            The result of the function if `self` is an :meth:`Result.Ok` value,
             otherwise returns `self`.

        Examples:
            >>> def sq(x): return Ok(x * x)
            >>> def err(x): return Err(x)
            >>> Ok(2).flatmap(sq).flatmap(sq)
            Ok(16)
            >>> Ok(2).flatmap(sq).flatmap(err)
            Err(4)
            >>> Ok(2).flatmap(err).flatmap(sq)
            Err(2)
            >>> Err(3).flatmap(sq).flatmap(sq)
            Err(3)
        """
        return op(cast(T, self._val)) if self._is_ok else cast('Result[U, E]', self)