-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.8] Added Tappable trait #28507
[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
tap
function to any class and remove the need for temporary variables. I've used it in the case wheredoSomething
anddoSomethingElse
don't return the instance :)