src/Utils/Utils.php
public static function filter($traversable, callable $predicate)
    {
        self::invariant(
            is_array($traversable) || $traversable instanceof Traversable,
            __METHOD__ . ' expects array or Traversable'
        );

        $result = [];
        $assoc  = false;
        foreach ($traversable as $key => $value) {
            if (! $assoc && ! is_int($key)) {
                $assoc = true;
            }
            if (! $predicate($value, $key)) {
                continue;
            }

            $result[$key] = $value;
        }

        return $assoc ? $result : array_values($result);
    }
public static function filter($traversable, callable $predicate)
    {
        self::invariant(
            is_array($traversable) || $traversable instanceof Traversable,
            __METHOD__ . ' expects array or Traversable'
        );

        $result = [];
        $assoc  = false;
        foreach ($traversable as $key => $value) {
            if (! $assoc && ! is_int($key)) {
                $assoc = true;
            }
            if (! $predicate($value, $key)) {
                continue;
            }

            $result[$key] = $value;
        }

        return $assoc ? $result : array_values($result);
    }
@param mixed|Traversable $traversable

@return mixed[]

@throws Exception