Created
December 3, 2018 10:54
-
-
Save minedun6/1d8609f2e44c4371fdc9c246a8dc25e4 to your computer and use it in GitHub Desktop.
Laravel "some" macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Collection::macro('some', function ($callback) { | |
return !! $this->first(function ($value, $key) use ($callback) { | |
return $callback($value, $key); | |
}); | |
}); | |
// use case | |
collect([1, 2, 3, 4])->some(function ($value) { | |
return $value > 2; | |
}); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment