Open utterances-bot opened 3 years ago
Cool, thanks for the explanation.
I noticed that it allows for values to be passed by reference. (also cool)
$multiplier = 2;
tap("5", function (&$value), use($multiplier) { $value = $multiplier * $value; });
The result will be 10
But if the callback return type is boolean (if it has a return value atall), it will simply return the first argument (the value)
Thx for the post.
Now, you might argue that it's less readable.
Yes, I do.
All examples you linked in the Laravel code base make it worst to read. All for the sake of removing a temp var? So in fn ($value) =>
$value is not a temp var? Not to mention the messed up call stack by anonymous functions. Sorry, I don't see the benefit.
Laravel's tap helper function explained - Freek Van der Herten's blog on PHP, Laravel and JavaScript
https://freek.dev/694-laravels-tap-helper-function-explained