Skip to content

Commit

Permalink
Merge pull request #10 from Jordan-Kowal/chore/keep-same-pipestart-th…
Browse files Browse the repository at this point in the history
…rough-pipe

chore: keep same PipeStart object throughout the pipe
  • Loading branch information
Jordan-Kowal authored Nov 22, 2024
2 parents 3e3834d + 5117cb0 commit 2772eef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 2772eef

Please sign in to comment.