Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Created January 11, 2016 15:28
Show Gist options
  • Select an option

  • Save mrbobbybryant/f6dc995364bd3052aa93 to your computer and use it in GitHub Desktop.

Select an option

Save mrbobbybryant/f6dc995364bd3052aa93 to your computer and use it in GitHub Desktop.
array_filter wrapper
<?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