The Pipe Operator

Read the RFC Externals
87
253 yes
119 no

The "pipe operator" |> allows you to chain multiple function calls in a more convenient way.

$result = "Hello World"
    |> 'htmlentities'
    |> 'str_split'
    |> fn($x) => array_map('strtoupper', $x)
    |> fn($x) => array_filter($x, fn($v) => $v != 'O');

This RFC was already declined, but we're sharing it here as another test RFC, and because it'd be interesting to learn people's opinion about it.

Click the bar to cast your vote!
68%
32%
1

It's nice to have.

Share:
stanislav-janu avatar
stanislav-janu
voted yes
1

I don't see any advantages and the syntax is a mess.

Share:
uli avatar
uli
voted no
1

functions as strings? Bro no way

Share:
pimjansen avatar
pimjansen
voted no
1

Improves readabillity drastically

Share:
aradoje avatar
aradoje
voted yes
1

Neat with first class callable syntax

Share:
sandermuller avatar
sandermuller
voted yes
1

It makes chain calls easier

Share:
maureis avatar
maureis
voted yes
1

First, it's really mostly syntactic sugar, adding cognitive load for no added Language-level feature. Besides, it's not clear how easy it would be to step over this code with a debugger.

Second, the argument that the equivalent nested function calls is much less readable, is sound but I think a developer should write neither. Both nested functions calls and chained function calls are hard to live-debug and hard to read, and most of the time in my experience are also an unnecessary micro-optimization.

Third, I think this specific operator "|>" isn't easy to type. The "->" member operator was a mistake of the past, we are stuck with it, don't make another one.

Share:
agc avatar
agc
voted no
1

Makes code more readable because has the natural direction of reading (if reading left-to-right, of course)

Share:
daviscaics avatar
daviscaics
voted yes
1

There is a chain of responsibilities patter that does exactly the same, so I don't see any reason to implement this.

Share:
piotrfilipek avatar
piotrfilipek
voted no
1

This doesn't appear in any popular language and does not bring any benefit to readability.

Share:
riki137 avatar
riki137
voted no
1

this actually looks not pretty

Share:
sunxyw avatar
sunxyw
voted no
1

I think it's a very nice way to simplify code. For me it looks readable and cleaner without the need of creating temporal variables.

Share:
marcmorente avatar
marcmorente
voted yes
1

It's not crucial, but it's gonna make code more readable and clear in a way. But It would be even greater if we had literals for passing functions instead of strings, (e.g. |> htmlentities(...) instead of |> 'htmlentities').

Share:
ozahorulia avatar
ozahorulia
voted yes
1

The new syntax is noisy. It adds more cognitive load to the currently available function invocation methods.

The existing libraries supporting pipelining do it fine without extending the language syntax.

Share:
anibalsanchez avatar
anibalsanchez
voted no
1

PHP is well known for "historic growth", i.e. internal functions often may return false instead of throwing an exception. I feel that using syntactic sugar to allow to travel the "optimistic path" (simply assuming the involved functions do not return false) is a bad idea.

Share:
invisiblesmiley avatar
invisiblesmiley
voted no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!