Live data from Hacker News

PHP 8.5 adds pipe operator

thephp.foundation

151–160 of 282 posts

Re: PHP 8.5 adds pipe operator

#151

The first typed programming language where I've seen pipe operator |> in action was in F#. You can write something like: sum 1 2 |> multiply 3 and it works because |> pushes the output of the left expression as the last parameter into the right-hand function. multiply has to be defined as: let multiply b c = b \* c so that b becomes 3, and c receives the result of sum 1 2 . RHS can also be a lambda too: sum 1 2 |> (f…

F# is excellent. It’s tooling, ecosystem, and compile times are the reason I don’t use it. I learned it alongside OCaml, and OCaml’s compilation speed spoiled me. It is indeed a shame that F# never became a first class citizen.

Lots of this, especially the tooling and ecosystem, improved considerably in the last couple of years.

OCaml is a great language, as are others in the ML family. Isabelle is the first language that has introduced the |> pipe character, I think.

Re: PHP 8.5 adds pipe operator

#152

Earlier quoted context omitted.

It’s really not needed, syntax sugar. With dots you do almost the same. Php doesn’t have chaining. Adding more and more complexity doesn’t make a language better.

I'm tired of hearing the exact same arguments, "not needed", "just syntax sugar", "too much complexity", about every new syntax feature that gets added to JS. Somehow, once they are in the language, nobody's head explodes, and people are soon using them and they become uncontroversial. If people really this new syntax will make it harder to code in JS, show some evidence. Produce a study on solving representative tas…

Presumably it's up to the change proposers to produce said study showing the opposite.

Re: PHP 8.5 adds pipe operator

#153

Earlier quoted context omitted.

Genuine question from a non-PHP user: Does PHP support iterator-like objects? Like Python I mean, where mydict.values() produces values on demand, not immediately realised as a list. Or are all steps necessarily guaranteed to be fully realised into a complete list?

yes, for a long time - https://www.php.net/manual/en/class.iterator.php

Interesting, but I suppose I was particularly interested if that's what's actually happening with the transformations in the example in the article. Are those making use of this protocol? The comment I originally replied to seems to imply they aren't.

Re: PHP 8.5 adds pipe operator

#154
Reminds me of D's Uniform Function Call Syntax[0], which allows you to rewrite bar(foo(sort(myArray))) as myArray.sort().foo().bar(). The difference is that D allows extra function arguments, keeping the passed-in value as the first argument. So you could have myArray.sort().writeln("extra text"), for example.

[0]: https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...

Re: PHP 8.5 adds pipe operator

#157
post #4

While I appreciate the effort and like the approach in general, in this use case I really would prefer extensions / extension functions (like in Kotlin[1]) or an IEnumerable / iterator approach (like in C#). $arr = [ new Widget(tags: ['a', 'b', 'c']), new Widget(tags: ['c', 'd', 'e']), new Widget(tags: ['x', 'y', 'a']), ]; $result = $arr |> fn($x) => array_column($x, 'tags') // Gets an array of arrays |> fn($x) => ar…

Basically what Collections do in Laravel.

Re: PHP 8.5 adds pipe operator

#158

Earlier quoted context omitted.

It’s really not needed, syntax sugar. With dots you do almost the same. Php doesn’t have chaining. Adding more and more complexity doesn’t make a language better.

I'm tired of hearing the exact same arguments, "not needed", "just syntax sugar", "too much complexity", about every new syntax feature that gets added to JS. Somehow, once they are in the language, nobody's head explodes, and people are soon using them and they become uncontroversial. If people really this new syntax will make it harder to code in JS, show some evidence. Produce a study on solving representative tas…

[dead]

Re: PHP 8.5 adds pipe operator

#159
post #29

Earlier quoted context omitted.

PHP string / array functions are consistent. string functions use (haystack, needle) and array functions use (needle, haystack) because that's the way the underlying C libraries also worked

So they are consistent because they are consistently inconsistent?? There isn't a good reason for PHP to have inherited C's issues here.

In the early days of PHP, it relied heavily on wrapping the underlying C libraries and preserving their naming conventions.

https://news-web.php.net/php.internals/70950

Re: PHP 8.5 adds pipe operator

#160
post #4

While I appreciate the effort and like the approach in general, in this use case I really would prefer extensions / extension functions (like in Kotlin[1]) or an IEnumerable / iterator approach (like in C#). $arr = [ new Widget(tags: ['a', 'b', 'c']), new Widget(tags: ['c', 'd', 'e']), new Widget(tags: ['x', 'y', 'a']), ]; $result = $arr |> fn($x) => array_column($x, 'tags') // Gets an array of arrays |> fn($x) => ar…

Basically what Collections do in Laravel.

Exactly... similar in Symfony.

While converting arrays to collection-object is a suitable option that does work, it would feel much more "native", if there were extension methods for Iterable / Traversable.

Post reply on HN