Live data from Hacker News

PHP 8.5 adds pipe operator

thephp.foundation

201–210 of 282 posts

Re: PHP 8.5 adds pipe operator

#201
post #2

Meanwhile the JS world has been waiting for 10 years for this proposal, which is still in stage 2 https://github.com/tc39/proposal-pipeline-operator/issues/23...

Sadly they went obsessing over pipes with promises which don't fit the natural flow.

Go explain them that promises already have a natural way to chain operations through the "then" method, and don't need to fit the pipe operator to do more than needed.

Re: PHP 8.5 adds pipe operator

#202

PHP: $result = $arr |> fn($x) => array_column($x, 'tags') // Gets an array of arrays |> fn($x) => array_merge(...$x) // Flatten into one big array |> array_unique(...) // Remove duplicates |> array_values(...) // Reindex the array. ; // Ruby: result = arr.uniq.flatten.map(&:tags) I understand this is not pipe operator, but just look at that character difference across these two languages. // This comment was my $0.02…

The trailing semi-colon on a new line helps prevent Git conflicts and gives cleaner diffs.

It's the same reason PHP allows trailing commas in all lists.

Re: PHP 8.5 adds pipe operator

#203

Earlier quoted context omitted.

What makes you believe Haskell is dead or even dying? New versions of GHC are coming out, and in my experience, developing Haskell has never been smoother (that’s not to say it is completely smooth).

And yet, while PHPs, Javas, and even nicher/newer languages like Kotlin, Clojure or Scala have plenty of killer software (software that makes it worth learning a language just to use that library/framework) Haskell has none after 30 years. Zero. Mind you, I know and like Haskell, but its issues are highly tied to the failure of the simple haskell initiative (also the dreadful state of its tooling).

yea I agree. haskell was my primary language for several years in the 00s. it's since had almost zero industry uptake. Don't come at me with jane street or the one off startup.

I thought for a while I'd be able to focus on getting jobs that liked haskell. it never happened.

Re: PHP 8.5 adds pipe operator

#204
post #170

Earlier quoted context omitted.

Haskell seems pretty dead as well. Good think php has another option for line noise though.

What makes you believe Haskell is dead or even dying? New versions of GHC are coming out, and in my experience, developing Haskell has never been smoother (that’s not to say it is completely smooth).

it's easy to learn and speak latin as well.

Re: PHP 8.5 adds pipe operator

#206

Earlier quoted context omitted.

What makes you believe Haskell is dead or even dying? New versions of GHC are coming out, and in my experience, developing Haskell has never been smoother (that’s not to say it is completely smooth).

And yet, while PHPs, Javas, and even nicher/newer languages like Kotlin, Clojure or Scala have plenty of killer software (software that makes it worth learning a language just to use that library/framework) Haskell has none after 30 years. Zero. Mind you, I know and like Haskell, but its issues are highly tied to the failure of the simple haskell initiative (also the dreadful state of its tooling).

It has PostgREST, which is the heart of supabase

Re: PHP 8.5 adds pipe operator

#207

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…

Is |> actually an operator in F#? I think it's just a regular function in the standard library but maybe I'm remembering incorrectly.

Re: PHP 8.5 adds pipe operator

#208
post #58

Earlier quoted context omitted.

This is "english-sentence-order-consistent", as it goes. Array filter is "filter this array with this function". Array map is "map this function over this array". But I agree any replacement function should be consistent with Haskell.

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"

But thats not correct. array_map is variadic. So it should actually be "Map over these arrays with this function."

When you use the correct verbiage, the parameter order makes sense.

Re: PHP 8.5 adds pipe operator

#209
post #142

I had this argument in the PHP community when the feature was being discussed, but I think the syntax is much more complicated to read , requiring backtracking to understand. It might be easier to write. Imagine you're just scanning code you're unfamiliar with trying to identify the symbols. Make sense of inputs and outputs, and you come to something as follows. $result = $arr |> fn($x) => array_column($x, 'values')…

People use method chaining all the time and don't have any issue with it? It's equivalent to something like:

    $result = $arr
        ->column('values')
        ->merge()
        ->reduce(fn($carry, $item) => $carry + $item, 0)
        ->repeat('x');
I think this just comes down to familiarity.

Re: PHP 8.5 adds pipe operator

#210
post #144

I'm confused about the rationale behind: |> fn($x) => array_column($x, 'tags') Why is that inlined function necessary? Why not just |> array_column(..., 'tags') ? I mean, I understand that it is because the way this operator was designed. But why?

> |> array_column(..., 'tags')

This syntax is invalid. But it will be possible next year with the proposed partial function application rfc

array_column(?, 'tags')

https://wiki.php.net/rfc/partial_function_application_v2

Post reply on HN