example\MaybeMonadAndCollectionTest::test_it_should_extract_elements_which_exists_alternative_solution PHP Метод

test_it_should_extract_elements_which_exists_alternative_solution() публичный Метод

    public function test_it_should_extract_elements_which_exists_alternative_solution($data)
    {
        // $get :: String a -> Maybe [b] -> Maybe b
        $get = function ($key) {
            return f\bind(function ($array) use($key) {
                return isset($array[$key]) ? m\just($array[$key]) : m\nothing();
            });
        };
        $result = Listt::of($data)->map(Maybe\maybeNull)->bind($get('meta'))->bind($get('images'))->bind($get(0));
        $this->assertEquals(Listt::of([m\just('//first.jpg'), m\just('//third.jpg'), m\nothing()]), $result);
    }