Created
January 11, 2016 15:28
-
-
Save mrbobbybryant/f6dc995364bd3052aa93 to your computer and use it in GitHub Desktop.
array_filter wrapper
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 | |
| $users = array( 'John', "Bobby", 'Alex' ); | |
| function filter( $fn ) { | |
| return function( $arr ) use ( $fn ) { | |
| return array_filter( $arr, $fn ); | |
| }; | |
| } | |
| function get( $value ) { | |
| return function( $el ) use ( $value ) { | |
| return $el === $value; | |
| }; | |
| } | |
| function get_user( $username, $users ) { | |
| $find = filter( get( $username ) ); | |
| return either( return_error( 'Users not found' ), $find( $users ) ); | |
| } | |
| var_dump( get_user( 'Bobby', $users ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment