Exemplo n.º 1
0
 /**
  * Alias: unique
  *
  * @chainable
  * @category  Arrays
  * @param     array            $xs
  * @param     callable|string  $f
  * @return    array
  */
 public static function uniq($xs, $f = null)
 {
     $f = static::createCallback($f);
     $set = new Internal\Set();
     $result = [];
     foreach ($xs as $k => $x) {
         if ($set->add(call_user_func($f, $x, $k, $xs))) {
             $result[$k] = $x;
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Alias: unique
  *
  * @chainable
  * @category  Arrays
  * @param     array            $xs
  * @param     callable|string  $f
  * @return    Generator
  */
 public static function uniq($xs, $f = null)
 {
     $f = static::createCallback($f);
     $set = new Internal\Set();
     foreach ($xs as $k => $x) {
         if ($set->add(call_user_func($f, $x, $k, $xs))) {
             (yield $k => $x);
         }
     }
 }