[5.8] Added Tappable trait#28507
Conversation
|
I feel this is unnecessary to add this to the core framework and something you can just use in your own codebase if you want to. |
|
You can publish this trait to a package. |
|
Isn't that the same as |
|
I don't see what this would've solved but I may be overlooking something. |
The // without tap
$tappable = TappableClass::make();
$tappable->doSomething();
$tappable->doSomethingElse();
$result = $tappable->getResult();
// with tap method
$result = tap(TappableClass::make(), function ($tappable) {
$tappable->doSomething();
$tappable->doSomethingElse();
})->getResult();
// with Tappable trait
$result = TappableClass::make()->tap(function ($tappable) {
$tappable->doSomething();
$tappable->doSomethingElse();
})->getResult();I prefer to call the |
|
I can't resist this. ❤️ |
|
@pascalbaljet would you mind sending a PR to the docs to explain this? |
|
@devcircus yes! |
|
Not sure exactly where the best place for this would be in the docs but otherwise it would mostly go unnoticed in the framework. |
A little helper trait to add the
tapfunction to any class and remove the need for temporary variables. I've used it in the case wheredoSomethinganddoSomethingElsedon't return the instance :)