Last active
December 28, 2015 15:48
-
-
Save igorw/7523904 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require 'vendor/autoload.php'; | |
use MonadPHP\ListMonad; | |
use MonadPHP\Maybe; | |
function index($key) { | |
return function ($arr) use ($key) { | |
return isset($arr[$key]) ? $arr[$key] : null; | |
}; | |
} | |
$photos = [ | |
['member' => ['name' => 'Igor']], | |
['member' => ['name' => 'Rafael']], | |
['random' => 'garbage'], | |
['member' => ['more' => 'random garbage']], | |
]; | |
$photos = new ListMonad($photos); | |
$names = $photos | |
->bind(MonadPHP\Maybe::unit) | |
->bind(index('member')) | |
->bind(index('name')) | |
->extract(); | |
var_dump(array_filter($names)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment