Permalink
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (24 sloc) 643 Bytes

filter

Description

Iterates over each value in the collection passing them to the callback function. If the callback function returns true, the current value from collection is returned into the result collection. Keys are preserved.

Parameters

fn
Filter to apply to every item in the collection.
coll
Collection of values to be filtered.

Examples

Filter numbers biggers than 10:

<?php

use function Lambdish\Phunctional\filter;

return filter(
    function ($number) {
        return $number > 10;
    }, 
    [1, 20, 3, 40, 5]
);
            
// => [20, 40]