Skip to content

Instantly share code, notes, and snippets.

@igorw
Last active December 28, 2015 15:48
Show Gist options
  • Save igorw/7523904 to your computer and use it in GitHub Desktop.
Save igorw/7523904 to your computer and use it in GitHub Desktop.
<?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