Alias: unique

@chainable
@category  Arrays
@param     array            $xs
@param     callable|string  $f
@return    Generator
325377
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;
            }
        }
    }
195324
public static function unique($array)
    {
        $unique = array();
        foreach ($array as $item) {
            if (!in_array($item, $unique, true)) {
                $unique[] = $item;
            }
        }

        return $unique;
    }
1359009
public function unique(array $elements, Closure $iterator = null)
    {
        if ( ! is_null($iterator))
        {
            $elements = array_filter($elements, $iterator);
        }
        else
        {
            $elements = array_unique($elements);
        }

        return array_values($elements);
    }
265424
function unique(oldArray) {
    var nIndex,
      nLen = oldArray.length,
      aArr = [];
    for (nIndex = 0; nIndex < nLen; nIndex++) {
      if (!contains(aArr, oldArray[nIndex][1])) {
        aArr.push(oldArray[nIndex]);
      }
    }
    return aArr;
  }
234240
public static function arrayFilterRecursive(Array $source, $fn)
    {
        $result = [];
        foreach ($source as $key => $value) {
            if (is_array($value)) {
                $result[$key] = static::arrayFilterRecursive($value, $fn);
                continue;
            }
            if ($fn($key, $value)) {
                $result[$key] = $value; // KEEP
                continue;
            }
        }

        return $result;
    }
1096290
public function create(array $aliases): HeaderCheckerManager
    {
        $checkers = [];
        foreach ($aliases as $alias) {
            if (\array_key_exists($alias, $this->checkers)) {
                $checkers[] = $this->checkers[$alias];
            } else {
                throw new \InvalidArgumentException(\sprintf('The header checker with the alias "%s" is not supported.', $alias));
            }
        }

        return HeaderCheckerManager::create($checkers, $this->tokenTypes);
    }
130863
function create( &$xmls ) {
		$sql = array();

		// drop any existing indexes
		if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) {
			foreach( $legacy_indexes as $index => $index_details ) {
				$sql[] = $xmls->dict->DropIndexSQL( $index, $this->name );
			}
		}

		// remove fields to be dropped from table object
		foreach( $this->drop_field as $field ) {
			unset( $this->fields[$field] );
		}

		// if table exists
		if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) {
			// drop table
			if( $this->drop_table ) {
				$sql[] = $xmls->dict->DropTableSQL( $this->name );

				return $sql;
			}

			// drop any existing fields not in schema
			foreach( $legacy_fields as $field_id => $field ) {
				if( !isset( $this->fields[$field_id] ) ) {
					$sql[] = $xmls->dict->DropColumnSQL( $this->name, $field->name );
				}
			}
		// if table doesn't exist
		} else {
			if( $this->drop_table ) {
				return $sql;
			}

			$legacy_fields = array();
		}

		// Loop through the field specifier array, building the associative array for the field options
		$fldarray = array();

		foreach( $this->fields as $field_id => $finfo ) {
			// Set an empty size if it isn't supplied
			if( !isset( $finfo['SIZE'] ) ) {
				$finfo['SIZE'] = '';
			}

			// Initialize the field array with the type and size
			$fldarray[$field_id] = array(
				'NAME' => $finfo['NAME'],
				'TYPE' => $finfo['TYPE'],
				'SIZE' => $finfo['SIZE']
			);

			// Loop through the options array and add the field options.
			if( isset( $finfo['OPTS'] ) ) {
				foreach( $finfo['OPTS'] as $opt ) {
					// Option has an argument.
					if( is_array( $opt ) ) {
						$key = key( $opt );
						$value = $opt[key( $opt )];
						@$fldarray[$field_id][$key] .= $value;
					// Option doesn't have arguments
					} else {
						$fldarray[$field_id][$opt] = $opt;
					}
				}
			}
		}

		if( empty( $legacy_fields ) ) {
			// Create the new table
			$sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );
			logMsg( end( $sql ), 'Generated CreateTableSQL' );
		} else {
			// Upgrade an existing table
			logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" );
			switch( $xmls->upgrade ) {
				// Use ChangeTableSQL
				case 'ALTER':
					logMsg( 'Generated ChangeTableSQL (ALTERing table)' );
					$sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts );
					break;
				case 'REPLACE':
					logMsg( 'Doing upgrade REPLACE (testing)' );
					$sql[] = $xmls->dict->DropTableSQL( $this->name );
					$sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );
					break;
				// ignore table
				default:
					return array();
			}
		}

		foreach( $this->indexes as $index ) {
			$sql[] = $index->create( $xmls );
		}

		if( isset( $this->data ) ) {
			$sql[] = $this->data->create( $xmls );
		}

		return $sql;
	}
167133
public static function iterator($xs)
    {
        if (is_array($xs)) {
            return new \ArrayIterator($xs);
        }
        if (!$xs instanceof \Iterator) {
            throw new \InvalidArgumentException();
        }
        return $xs;
    }
561409
public function unique($properties)
    {
        $properties = (array) $properties;

        foreach ($properties as $property)
        {
            $this->addCommand('unique', ['property' => $property]);
        }
    }
1091797
public function unique() : Collection
    {
        return $this->pipe(
            self::predicate(
                function (array $values) : bool {
                    return array_unique($values) === $values;
                },
                'not all unique elements'
            )
        );
    }
683405
function array_merge_recursive_unique($array1, $array2)
	{
		$arrays = func_get_args();
		$narrays = count($arrays);
		$ret = $arrays[0];
		for ($i = 1; $i < $narrays; $i ++) {
			foreach ($arrays[$i] as $key => $value) {
				if (((string) $key) === ((string)((int) $key))) { // integer or string as integer key - append
					$ret[] = $value;
				} else { // string key - merge
					if (is_array($value) && isset($ret[$key])) {
						$ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
					} else {
						$ret[$key] = $value;
					}
				}
			}
		}
		return $ret;
	}
1259126
function unique(arr) {
  var ret = [];

  for (var i = 0; i < arr.length; i++) {
    if (~ret.indexOf(arr[i])) continue;
    ret.push(arr[i]);
  }

  return ret;
}
220381
function unique(arr) {
    return arr.filter(function (value, idx, self) {
        return self.indexOf(value) === idx;
    });
}
88463
function unique($key, $options = \SORT_REGULAR) {
        if($key === null) {
            return (new self(\array_unique($this->data, $options)));
        }
        
        $exists = array();
        return $this->filter(function ($item) use ($key, &$exists) {
            if(\is_array($item)) {
                if(!isset($item[$key])) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on array');
                }
                
                $id = $item[$key];
            } elseif(\is_object($item)) {
                if(!isset($item->$key)) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on object');
                }
                
                $id = $item->$key;
            } else {
                $id = $item;
            }
            
            if(\in_array($id, $exists, true)) {
                return false;
            }
            
            $exists[] = $id;
            return true;
        });
    }
840189
static function setAlias($name, $alias)
    {
        if (!is_array($alias))
            $alias = array($alias);

        foreach($alias as $a)
            self::$_aliases[(string) $a] = (string) $name;
    }
1015860
public static int[] unique(int[] x) {
        HashSet<Integer> hash = new HashSet<>();
        for (int i = 0; i < x.length; i++) {
            hash.add(x[i]);
        }

        int[] y = new int[hash.size()];

        Iterator<Integer> keys = hash.iterator();
        for (int i = 0; i < y.length; i++) {
            y[i] = keys.next();
        }

        return y;
    }
989244
public static function getInstance(array $aliases = array())
	{
		if (is_null(static::$instance)) static::$instance = new static($aliases);
		
		$aliases = array_merge(static::$instance->getAliases(), $aliases);

		static::$instance->setAliases($aliases);

		return static::$instance;
	}