/** * 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; }
/** * 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); } } }