Menu

1 / 2

Fixing the array functions for the pipe operator

DEV Community·david duymelinck·7 months ago
#daDsPKuE
#php#software#coding#development#user
Reading 0:00
15s threshold

I had a good conversation with @delacry over the library that was introduced .

And what struck me the most was the last example.

$topAdmins = $users |> array_filter ( ? , fn ( User $u ) => $u -> isActive ()) |> array_map ( fn ( User $u ) => $u -> refresh (), ? ) |> array_filter ( ? , fn ( User $u ) => $u -> isAdmin ()) |> ( fn ( $us ) => ( usort ( $us , fn ( User $a , User $b ) => $a -> name <=> $b -> name ) ? $us : $us )) |> array_slice ( ? , 0 , 10 );

Enter fullscreen mode

Exit fullscreen mode

It is an example with the upcoming partial function application change (PHP 8.6).

I do agree, while it looks miles better than it is in PHP 8.5, it still is not that straight forward as the solutions with the builder pattern.

So I took a bit of time off from my dates project to come up with PAF . POAF looked weird to me, and PAF reminded me of a thing we said in Dutch when I was young, pief poef paf.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.