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
13 changes: 5 additions & 8 deletions src/danom/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import itertools
import os
from abc import ABC, abstractmethod
from collections.abc import Awaitable, Callable, Iterable, Sequence
from collections.abc import Awaitable, Callable, Iterable
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from copy import deepcopy
from enum import Enum
Expand Down Expand Up @@ -481,13 +481,10 @@ def _apply_fns_worker[T](args: tuple[tuple[T], tuple[PlannedOps, ...]]) -> tuple

@attrs.define(frozen=True, hash=True, eq=True)
class _Tap:
fns: Sequence[Callable]
fn: Callable

def __call__(self, initial: T) -> T:
return reduce(self._apply, self.fns, initial)

def _apply[T](self, value: T, fn: Callable[[T], None]) -> T:
deepcopy(fn(value))
def __call__(self, value: T) -> T:
deepcopy(self.fn(value))
return value


Expand All @@ -499,7 +496,7 @@ def _apply_fns[T](elements: tuple[T], ops: tuple[PlannedOps, ...]) -> tuple[T, .
elif op == _FILTER:
pipeline = filter(fn, pipeline)
elif op == _TAP:
pipeline = map(_Tap((fn,)), pipeline)
pipeline = map(_Tap(fn), pipeline)
else:
raise RuntimeError("Invalid operation selected. Valid options [map, filter, tap]")

Expand Down
Loading