diff --git a/src/danom/_stream.py b/src/danom/_stream.py index cdc07ae..2fce985 100644 --- a/src/danom/_stream.py +++ b/src/danom/_stream.py @@ -21,6 +21,7 @@ U = TypeVar("U") E = TypeVar("E") P = ParamSpec("P") +S = TypeVar("S", bound="_BaseStream") MapFn = Callable[P, U] FilterFn = Callable[P, bool] @@ -68,6 +69,11 @@ def fold( self, initial: T, fn: Callable[[T, U], T], *, workers: int = 1, use_threads: bool = False ) -> T: ... + @abstractmethod + def sequence( + self, *, workers: int = 1, use_threads: bool = False + ) -> Result[S, E] | Either[S, E]: ... + @abstractmethod def collect(self) -> tuple[U, ...]: ... @@ -337,8 +343,8 @@ def partition( return (Stream.from_iterable(pos), Stream.from_iterable(neg)) def sequence( - self, *, workers: int = 1, use_threads: bool = False - ) -> Result[T, E] | Either[T, E]: + self: Stream[T], *, workers: int = 1, use_threads: bool = False + ) -> Result[Stream[T], E] | Either[Stream[T], E]: """Convert a ``Stream`` of ``Result`` or ``Either`` monads to a monad of Stream .. doctest::