Feat: Add Pythonic Pipeline pattern using functional composition #461
+118
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Pythonic implementation of the Pipeline (Functional Pipeline) pattern to the repository.
The example demonstrates how sequential data processing can be composed using callables, iterables, and generators, instead of class-heavy or framework-style abstractions. The goal is to provide a clear, minimal reference that aligns with common Python idioms.
Motivation
While the repository includes many classic GoF and architectural patterns, it did not previously contain a dedicated example of the Pipeline pattern, which is widely used in Python for:
Adding this pattern fills a practical gap and reflects how Python developers commonly structure such flows.
Files Changed
Added
patterns/behavioral/pipeline.pyAdds a Pythonic implementation of the Pipeline (Functional Pipeline) pattern,
including a short TL;DR, minimal implementation, and runnable example.
tests/test_pipeline.pyAdds a small test to verify pipeline composition and behavior.
Changed
README.mdAdds
pipelineto the list of behavioral patterns.Design & Implementation
The implementation focuses on simplicity and readability:
Iterableinto anotherIterablecomposehelper connects stages left-to-rightPipelinewrapper is included for convenience without introducing complex abstractionsExample
The included demonstration builds a pipeline that:
This illustrates how small, reusable stages can be combined into a readable data flow.
Testing
The behavior was verified by running the example included in the module.
Doc
Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=191372963