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

One-off pipes #94

Merged
merged 6 commits into from
Jan 7, 2024
Merged

One-off pipes #94

merged 6 commits into from
Jan 7, 2024

Conversation

YoraiLevi
Copy link
Contributor

partial-like syntax for pipe construction
#93

partial-like syntax for pipe construction
@YoraiLevi YoraiLevi marked this pull request as ready for review November 13, 2023 17:22
@JulienPalard
Copy link
Owner

It works, but is it really usefull? If you have a nice, striking example, please write it in the README.md to document the feature (without documentation it will never be used).

@YoraiLevi
Copy link
Contributor Author

YoraiLevi commented Dec 1, 2023

It naturally extends the pattern provided by the existing curying examples.
https://github.com/JulienPalard/Pipe#partial-pipes
Right after the curying example.
Possible doc:
Create a partially initialized custom pipe in one line

some_iterable | Pipe(some_func, 1, 2, 3)

It's a little bit hard to add a specific example that fits the readme pattern of decorating functions with Pipe since this syntax is a shorthand for it...

@JulienPalard
Copy link
Owner

Playing around itertools there's a few "interesing" ones we could pick:

>>> list(range(10) | Pipe(itertools.accumulate, initial=1))
[1, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46]
>>> list(range(10) | Pipe(itertools.batched, 2))
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>>> list(range(5) | Pipe(itertools.chain, range(5)))
[0, 1, 2, 3, 4, 0, 1, 2, 3, 4]
>>> list(range(5) | Pipe(itertools.combinations, r=2))
[(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
>>> list(range(20) | Pipe(itertools.compress, selectors=[1, 0] * 10))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
>>> list(range(20) | Pipe(itertools.compress, selectors=[0, 1] * 10))
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
>>> list(range(20) | Pipe(itertools.islice, 5, 10))
[5, 6, 7, 8, 9]

maybe based on this we can imagine a "good" example?

@YoraiLevi
Copy link
Contributor Author

YoraiLevi commented Dec 2, 2023

I think that all of the examples you've provided are good and demonstrate exactly my intentions with the syntax. However I still don't yet see how they fit the flow of the current documentation.

@JulienPalard
Copy link
Owner

Feels like it should be documented under # Constructing your own and before # Partial Pipes.

Feels like it goes near the end = Pipe(deque), maybe with an example using deque, like last_ten = Pipe(deque, maxlen=10)?

Just don't forget to run pytest in order to verify your examples (the test_readme test runs the README using the doctest module to validate all examples are true).

@YoraiLevi YoraiLevi changed the title Update pipe.py One-off pipes Jan 4, 2024
@YoraiLevi
Copy link
Contributor Author

Added section describing the usage to readme, "One-off pipes"

python -m tox -q

py38: SKIP ⚠ in 0.22 seconds
py39: SKIP ⚠ in 0.02 seconds
py310: SKIP ⚠ in 0.03 seconds
================================================================= test session starts =================================================================
platform win32 -- Python 3.11.3, pytest-7.4.4, pluggy-1.3.0
cachedir: .tox\py311\.pytest_cache
rootdir: C:\Users\devic\OneDrive\Documents\Sources\Pipe
plugins: hypothesis-6.92.2
collected 8 items

README.md .                                                                                                                                      [ 12%]
tests\test_pipe.py .......                                                                                                                       [100%]

================================================================== 8 passed in 1.73s ================================================================== 
py311: OK ✔ in 28.3 seconds
py312: SKIP ⚠ in 0.02 seconds
py313: SKIP ⚠ in 0.03 seconds
flake8: OK ✔ in 9.75 seconds
All done! ✨ 🍰 ✨
2 files would be left unchanged.
black: OK ✔ in 11.22 seconds

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

pylint: OK ✔ in 22.86 seconds
Combined data file .tox\.coverage.py311.abcdef-123.9148.XeajDSyx
Name    Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------
TOTAL     129      0     82      0   100%

1 file skipped due to complete coverage.
  py38: SKIP (0.22 seconds)
  py39: SKIP (0.02 seconds)
  py310: SKIP (0.03 seconds)
  py311: OK (28.30 seconds)
  py312: SKIP (0.02 seconds)
  py313: SKIP (0.03 seconds)
  flake8: OK (9.75 seconds)
  black: OK (11.22 seconds)
  pylint: OK (22.86 seconds)
  coverage: OK (8.00 seconds)
  congratulations :) (80.64 seconds)

@JulienPalard JulienPalard merged commit 2f16935 into JulienPalard:main Jan 7, 2024
5 checks passed
@JulienPalard
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants