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

support data pipelining |> #15

Open
christianparpart opened this issue Dec 18, 2023 · 0 comments
Open

support data pipelining |> #15

christianparpart opened this issue Dec 18, 2023 · 0 comments
Labels
enhancement New feature or request part:language Shell Language and Semantics

Comments

@christianparpart
Copy link
Member

christianparpart commented Dec 18, 2023

The |> operator (inspired from F# / Ocaml) would have the left hand side's stdout split into lines, and feed each line from left into a newly spawned process into the right.

echo "A \n B \n C" |> echo

would result into 3 echo processes, each receiving the parameter A, B, and C individually, resulting into the output:

A
B
C

That can then be chained into multiple, like in this example:

get_numbers |> times_two |> plus_one |> echo

where get_numbers prints N numbers (one per line), and times_two gets invoked N times and multiplies each number by 2, and plus_one gets invoked N times and adds 1 over the intermediate result, to then have each result printed, once per line.

notes

this is similar to what xargs -n1 does, but this syntactic shougar would not need to spawn the process xargs and have it more platform independant (e.g. xargs would not exist on Windows).

The syntax could make the code look more readable / maintainable as well.

@christianparpart christianparpart added part:language Shell Language and Semantics enhancement New feature or request labels Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request part:language Shell Language and Semantics
Projects
None yet
Development

No branches or pull requests

1 participant