Live data from Hacker News

PHP 8.5 adds pipe operator

thephp.foundation

91–100 of 282 posts

Re: PHP 8.5 adds pipe operator

#91
I'm surprised that the example requires lambdas... What's the purpose of the `|> foo(...)' syntax if the function has to take exactly one operand? Why is it necessary to write this?

    $arr
        |> fn($x) => array_column($x, 'tags')
Why doesn't this work?

    $arr
        |> array_column(..., 'tags')
And when that doesn't work, why doesn't this work?

    $arr
        |> array_unique

Re: PHP 8.5 adds pipe operator

#92
post #14
post #10

C'mon Dart! Follow up please. Go is a lost cause...

I feel like a kindergartener writing go. I wish another language got popular in the space go is used for.

Kotlin is shaping up slowly. It's kind of there with a native compiler that is getting better with each release and decent multiplatform libraries. It's a bit weak with support for native libraries and posix stuff. But that's a fixable issue; it just needs more people working on that.

For example ktor (one of the server frameworks) can actually work with Kotlin native but it's not that well supported. This is not using Graal or any of the JVM stuff at runtime (which of course is also a viable path but a lot more heavyweight). With Kotlin native, the Kotlin compiler compiles directly to native code and uses multiplatform libraries with native implementations. There is no Java standard library and none of the jvm libraries are used.

The same compiler is also powering IOS native with Compose multiplatform. On IOS libraries are a bit more comprehensive and it's starting to become a proper alternative to things like flutter and react native. It also has pretty decent objectc and swift integration (both ways) that they are currently working on improving.

In any case, it's pretty easy to write a command line thingy in Kotlin. Use Klikt or similar for command line argument parsing.

Jetbrains seems to be neglecting this a bit for some reason. It's a bit of a blind spot in my view. Their wasm support has similar issues. Works great in browsers (and supported with compose as well) but it's not a really obvious choice for serverless stuff or edge computing just yet; mainly because of the library support.

Swift is a bit more obvious but has the issue that Apple seems to think of it as a library for promoting vendor lockin on their OS rather than as a general purpose language. Both have quite a bit of potential to compete with Go for system programming tasks.

Re: PHP 8.5 adds pipe operator

#93
post #91

I'm surprised that the example requires lambdas... What's the purpose of the `|> foo(...)' syntax if the function has to take exactly one operand? Why is it necessary to write this? $arr |> fn($x) => array_column($x, 'tags') Why doesn't this work? $arr |> array_column(..., 'tags') And when that doesn't work, why doesn't this work? $arr |> array_unique

It is to interject the chained value at the right position in the function.

They write that elixir has a slightly fancier version, it is likely around this, they mean (where elixir has first class support for arity > 1 functions)

Re: PHP 8.5 adds pipe operator

#95
post #91

I'm surprised that the example requires lambdas... What's the purpose of the `|> foo(...)' syntax if the function has to take exactly one operand? Why is it necessary to write this? $arr |> fn($x) => array_column($x, 'tags') Why doesn't this work? $arr |> array_column(..., 'tags') And when that doesn't work, why doesn't this work? $arr |> array_unique

It is to interject the chained value at the right position in the function. They write that elixir has a slightly fancier version, it is likely around this, they mean (where elixir has first class support for arity > 1 functions)

But the example suggests that it can't interject the chained value at the right position; if that was the case, the example would've been written as `|> array_column('tags', ...)`.

Re: PHP 8.5 adds pipe operator

#96
post #58

Earlier quoted context omitted.

One can construct English sentences in the opposite order. There is no singular "English sentence order". "Filter for this function in this array" "Map over this array with this function"

Right, but these are both more unwieldy. One filters something with something else, in the real world. Filter water with a mesh etc. And (in maths, at least) one maps something onto something else. (And less commonly one maps an area onto paper etc.) Just because you can make your two sentences does not make them natural word order.

> And (in maths, at least) one maps something onto something else.

Yes, but that's the opposite of what you said earlier. You might map x onto 2*x, for example. Or, if you're talking about a collection, you might map the integers 0..10 on to double their value. Data first, then the way you're manipulating it. I'm a mathematician and this is what makes sense to me.

I would only say "map this function..." if the function itself is being manipulated somehow (mapped onto some other value).

Re: PHP 8.5 adds pipe operator

#97
Hm. Looks like PHP actually got a modern feature there, and it is looking decent, not like the usual new PHP feature, that just looks worse than in other languages, where it has been standard. Consider me surprised, that they seem to have done a good job on this one. And they even dodged the bullet with making the right side callables, which avoids the trap of inventing new types of expressions and then not covering all cases.

Re: PHP 8.5 adds pipe operator

#98
post #88
post #45

Earlier quoted context omitted.

I don't see how this is hard to reason about, assuming this is the resulting code when using variables: $tags = ...array_column($arr, 'tags'); $merged_tags = array_merge($tags); $unique_tags = array_unique($merged_tags); $tag_values = array_values($unique_tags); It also makes it easier to inspect the values after each step.

I don't think inspecting this is easier than adding |> IO.inspect() to a pipe chain

Or putting `|> dbg()` at the end and let it print the value at every step of the chain

Re: PHP 8.5 adds pipe operator

#99

Why not just make types psuedo-objects? $myString.trim().replace("w", "h"); Which has the advantage of also offering a clean alternative to the fragmented stdlib.

> Why not just make types psuedo-objects?

With this sort of "just" I could build Paris out of matchsticks

Re: PHP 8.5 adds pipe operator

#100
post #49
post #6

Earlier quoted context omitted.

Nothing is really needed, C89 was good enough. Dots are not the same, nobody wants to use chaining like underscore/lodash allowed because it makes dead code elimination impossible.

K&R C was good enough for UNIX System V, why bother with C89.

K&R C was the apex, we've just been going downhill since.
Post reply on HN