Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/danom/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def map[**P](self, func: Mappable, *args: P.args, **kwargs: P.kwargs) -> Self:
return self

def map_err[**P](self, func: Mappable, *args: P.args, **kwargs: P.kwargs) -> Err[E_co]:
return Err(func(self.error, *args, **kwargs))
return Err(
func(self.error, *args, **kwargs), input_args=self.input_args, traceback=self.traceback
)

def and_then[**P](self, func: Bindable, *args: P.args, **kwargs: P.kwargs) -> Self: # noqa: ARG002
return self
Expand Down
4 changes: 3 additions & 1 deletion src/danom/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __bool__(self) -> bool:

@attrs.define(frozen=True)
class Stream[T](_BaseStream):
"""An immutable lazy iterator with functional operations.
"""A lazy iterator with functional operations.

Why bother?
-----------
Expand Down Expand Up @@ -472,6 +472,8 @@ def par_collect(self, workers: int = 4, *, use_threads: bool = False) -> tuple[U
if workers == -1:
workers = (os.cpu_count() or 5) - 1

workers = max(workers, 1)

executor_cls = ThreadPoolExecutor if use_threads else ProcessPoolExecutor

batches = [
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def _get_attr_collect(stream: Stream, collect_fn: str, kwargs: dict) -> tuple:
pytest.param("collect", {}, id="simple `collect`"),
pytest.param("par_collect", {"workers": 4}, id="`par_collect` with workers passed in"),
pytest.param("par_collect", {"workers": -1}, id="`par_collect` with n-1 workers"),
pytest.param(
"par_collect", {"workers": 0}, id="`par_collect` with 0 workers falls back to 1 worker"
),
pytest.param("par_collect", {"use_threads": True}, id="`par_collect` with threads True"),
],
)
Expand Down