Closed
Description
I think Elixir's Pipe Operator would be a slam-dunk for Go.
Without a pipe operator, we write things like this:
s := strings.ReplaceAll(strings.ToLower(strings.TrimSpace(x)), "/old/", "/new")
// or this:
http.HandleFunc("/",
RequireAuthMiddleware(
SomeOtherMiddleware(
LogMiddleware(IndexHandler))))
Two complaints: 1) fussy parenthesis accounting, 2) text reads L-to-R, action happens R-to-L.
With a pipe operator, they could be re-written like this:
s := strings.TrimSpace(x) |> strings.ToLower() |> strings.ReplaceAll("/old/", "/new")
http.HandleFunc("/",
LogMiddleware(IndexHandler) |> SomeOtherMiddleware() |> RequireAuthMiddleware(),
)
It's a tad longer, but easier to read. The operations have more visual separation, and now both text and action flow left-to-right.
Elixir's pipe operator only passes the first parameter. For Go, it would probably make more sense to pipe as many parameters as the previous call returns.