Stream: ideas

Topic: Argument Ordering in Pipelines


view this post on Zulip Jose Quesada (Feb 22 2022 at 17:56):

I was looking at the FAQ for the absence of currying in Roc. I have a question and idea. I honestly don't expect it to go anywhere, but just a thought non-the-less.

Something I ran into issues a couple times with Elm and pipelines, is that I had to think ahead on how my function was going to be used in pipelines, or if at all, and structure my arguments to be compatible with that style.

Often times, I created a function with 3 or more arguments, and had to call the function from multiple different pipelines with the ordering of arguments changed, which wouldn't work. To solve this, I would create a helper function that would re-order the arguments the way I needed them. This worked, but was very unergonomic.

I am thinking, would something like this be desirable?
"!"
  1|> Str.concat "Hello, world"

By default, the argument could be passed in the first position (index could be from 0 or 1, but 0 is more consistant with everything else, and if you needed to, you could decide what position to apply the argument to.

"Hello, world"
  0|> Str.concat "!"

is the same as:

"Hello, world"
  |> Str.concat "!"

The biggest downside I would see to this notation would be the readability of the pipeline, having to actually think and check if the ordering has been modified. But I think it might be ok?

view this post on Zulip Tommy Graves (Feb 22 2022 at 18:07):

I do think it helps with ergonomics to allow you to pipe into more than just the first argument. Another option is to allow the use of _ as an indicator for where the argument should be piped to:

"!" |> Str.concat "Hello, world" _

I think the main downside of adding this feature is that it makes it harder to establish the convention that the first argument should always be the most commonly piped in one. And you can always express the same thing just by adding a helper function, like you said.

view this post on Zulip Jose Quesada (Feb 22 2022 at 19:39):

I actually like the _ much more

view this post on Zulip Richard Feldman (Feb 22 2022 at 20:01):

yeah I'm open to something like that, but want to set a pretty high bar for adding it

view this post on Zulip Richard Feldman (Feb 22 2022 at 20:01):

Scala and PureScript both have things like that

view this post on Zulip Richard Feldman (Feb 22 2022 at 20:01):

I think having |> be a forcing function for consistent argument ordering is a positive

view this post on Zulip Brendan Hansknecht (Feb 22 2022 at 20:01):

I like the feature, but I also question if it is worth adding rather than just using a pipe to a lambda.
|> \x -> Str.concat "Hello, world" x

view this post on Zulip Jose Quesada (Feb 22 2022 at 23:07):

Since |> already means "pass as the first argument", how about a different operator that would always require specifying where the pipe should pipe into?

Perhaps |>> ? Or |->
Although, I am not too big a fan of adding a new operator because I really enjoy the minimalism.
Overloading |> could work, but a new operator might be worth it.

view this post on Zulip Jose Quesada (Feb 22 2022 at 23:09):

Also not adding the feature as Brendan mentioned is also an option :)

view this post on Zulip Richard Feldman (Feb 22 2022 at 23:24):

yeah I think the current design is the most likely one to end up being the way to go

view this post on Zulip Richard Feldman (Feb 22 2022 at 23:24):

Elm has only one ordering for |> and I think it's worked well


Last updated: Jun 16 2026 at 16:19 UTC