diff --git a/CHANGELOG.md b/CHANGELOG.md index 9564d49..f5fc9e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pipe_operator/python_flow/pipe.py b/pipe_operator/python_flow/pipe.py index d70c561..80f616d 100644 --- a/pipe_operator/python_flow/pipe.py +++ b/pipe_operator/python_flow/pipe.py @@ -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: @@ -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."""