Esempio n. 1
0
 /**
  * Filter a list by calling a callback on each element.
  *
  * If the callback returns true, then the element will be added to the
  * resulting array. Otherwise, it will be skipped.
  *
  * Also, unlike array_filter, this function preserves indexes.
  *
  * @param callable $function
  * @param array|Traversable $traversable
  *
  * @return array
  */
 public static function filter(callable $function, $traversable)
 {
     Arguments::define(Boa::func(), Boa::traversable())->check($function, $traversable);
     $aggregation = [];
     foreach ($traversable as $key => $value) {
         if ($function($value, $key)) {
             $aggregation[$key] = $value;
         }
     }
     return $aggregation;
 }