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

Add a function pipe alongside methods #49

Open
mjkanji opened this issue Jan 2, 2025 · 1 comment
Open

Add a function pipe alongside methods #49

mjkanji opened this issue Jan 2, 2025 · 1 comment

Comments

@mjkanji
Copy link

mjkanji commented Jan 2, 2025

I didn't know quite how to word the title, but I'm basically suggesting a way to write streams of transformations in a style similar to this example in the Expression package.

In other words, consider the following:

my_list = list(Stream(it.product(*my_arrays)).truncate(some_limit).group(5))

Many Python formatters (like Ruff) will put the entire expressiion on one line, until it's total length would exceed some max line limit. This severely affects the readability of the code. It's better than nested function calls, but not by very much.

Until they resolve that (e.g., see astral-sh/ruff#8598), I'd like to be able to write the following:

my_list = stream_pipe(
    it.product(*my_arrays),
    truncate(some_list),
    group(5),
    list,
)

The comma after list would prevent the formatter from trying to put everything on the same line, which is crucial for readability.

@ebonnal
Copy link
Owner

ebonnal commented Jan 2, 2025

Hey @mjkanji. You are right that is so sad... It feels even sadder to introduce an alternative API just to compensate for that formatting issue 😢

What do you think about this hack:

my_list = list(
    Stream(it.product(*my_arrays))  #
    .truncate(some_limit)  #
    .group(5)
)

@ebonnal ebonnal added wontfix This will not be worked on and removed wontfix This will not be worked on labels Jan 9, 2025
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

No branches or pull requests

2 participants