My favorite pipeline is Elixir, where "The pipe operator |> passes the
result of an expression as the first parameter of another expression".. But
it works there because unlike with PHP, it's almost always the first
argument you want. If it's not the first argument you needed to do some
tricks which was only cleaned up in 2021 so now they do:

5
|> then(&Enum.take(1..10, &1))
|> Enum.reverse()

but I digress.

My problem here is... we actually need something that passes the RFC vote.

What flexibility is missing here?


On Tue, Jul 18, 2023 at 6:48 PM Larry Garfield <la...@garfieldtech.com>
wrote:

> On Tue, Jul 18, 2023, at 4:41 PM, Karoly Negyesi wrote:
> > So. Let's get back to pipelines.
> >
> > I wrote this email because I was manipulating a robots meta tag string:
> >
> > $robots_array = explode(', ', $robots_string);
> > $robots_array = array_diff($robots_array, $remove);
> > $robots_string = implode(', ', $robots_array);
> >
> > Very pipeline-ish.
> >
> > You could write a userspace pipeline
> > https://gist.github.com/chx/6638aba76d8b414ffedc7e5af78fb479 but this
> has
> > the advantage of being spectacularly ugly and slow as well.
> >
> > Just converting it into a pipeline with
> >
> > $robots_string
> > |>  fn ($x) => explode(', ', $x)
> > |> fn ($x) => array_diff($x, $remove)
> > |> fn ($x) => implode(', ', $x)
> >
> > has the same characteristics. What I would love to see:
> >
> > $robots_string
> > |> explode(', ', $)
> > |> array_diff($, $remove)
> > |> implode(', ', $)
> >
> > While that does look like partial function application, it does not need
> to
> > be. It could be just syntactic sugar. Namely, in the expression following
> > |> a $ is replaced by the entire expression before the |>. Step by step:
> >
> > explode(', ', $robots_string)
> > |> array_diff($, $remove)
> > |> implode(', ', $)
> >
> > array_diff(explode(', ', $robots_string), $remove)
> > |> implode(', ', $)
> >
> > implode(', ', array_diff(explode(', ', $robots_string), $remove))
> >
> > We could use any other symbol but I liked the $ sign here because the
> > entire point is not needing a temporary variable between steps so the $
> > sign stands for "unnamed temporary variable". I also believe it can't
> lead
> > to any ambiguous situation (famous last words).
> >
> > What do you think of this simple version?
>
> That's what Hack does, and what no other language does.  I dislike it as
> it's actually much less flexible overall.  It's also more work to implement.
>
> The original idea was that combining real PFA with a callable-based pipe
> would give us the same net effect if we wanted it, but with greater
> flexibility and more power across the whole language.  Unfortunately the
> PFA RFC barely didn't pass, due to its complexity.  A nicer implementation,
> if it could be found, would probably pass.
>
> --Larry Garfield
>

Reply via email to