Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: keep same PipeStart object throughout the pipe #10

Merged
merged 1 commit into from
Nov 22, 2024
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- 🐞 Bugfixes
- 🔧 Others

## TBD

- ✨ Keep same `PipeStart` object throughout the pipe for improved performances

## 1.0.4 - 2024-11-22

- ✨ Added `__slots__` to python implementation for improved performances
Expand Down
8 changes: 5 additions & 3 deletions pipe_operator/python_flow/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __rshift__(
Implements the `>>` operator to enable our pipe workflow.

3 possible cases based on what `other` is:
`Pipe/PipeArgs/Then` --> Classic pipe workflow where we return a new PipeStart with the result.
`Tap` --> Side effect where we call the function and a new PipeStart with the original value.
`Pipe/PipeArgs/Then` --> Classic pipe workflow where we return the updated PipeStart with the result.
`Tap` --> Side effect where we call the function and return the unchanged PipeStart.
`PipeEnd` --> Simply returns the raw value.

Return can actually be of 3 types, also based on what `other` is:
Expand All @@ -103,7 +103,9 @@ def __rshift__(
self._print_data(other.tap)
if other.tap:
return self # type: ignore
return PipeStart(self.result, debug=self.debug, chained=True)
# Performance: update self instead of creating a new PipeStart
self.value, self.result, self.chained = self.result, None, True # type: ignore
return self # type: ignore

def _print_data(self, is_tap: bool) -> None:
"""Will either its value, its result, or both."""
Expand Down
Loading