Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/danom/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Awaitable, Callable, Iterable, Sequence
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from copy import deepcopy
from enum import Enum, auto
from enum import Enum
from functools import reduce
from itertools import batched
from typing import ParamSpec, TypeVar, cast
Expand Down Expand Up @@ -312,10 +312,15 @@ def partition(
seq_tuple = self.par_collect(workers=workers, use_threads=use_threads)
else:
seq_tuple = self.collect()
return (
Stream(seq=tuple(x for x in seq_tuple if fn(x))),
Stream(seq=tuple(x for x in seq_tuple if not fn(x))),
)

pos, neg = [], []

for x in seq_tuple:
if fn(x):
pos.append(x)
else:
neg.append(x)
return (Stream.from_iterable(pos), Stream.from_iterable(neg))

def fold(
self, initial: T, fn: Callable[[T, U], T], *, workers: int = 1, use_threads: bool = False
Expand Down Expand Up @@ -442,7 +447,7 @@ async def async_collect(self) -> Awaitable[tuple[U, ...]]:


class _Nothing(Enum):
NOTHING = auto()
NOTHING = 0


PlannedOps = tuple[str, StreamFn]
Expand Down
Loading