code: 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);
      }
docs: @param mixed|Traversable $traversable
  
  @return mixed[]
  
  @throws Exception