txt: ## unique.md
  unique
  
  Combined from primary sources listed below.
  
  # [In Any](#___top "go to top of document")[§](#(Any)_method_unique "direct link")
  
  See primary documentation
  [in context](/type/Any#method_unique)
  for **method unique**.
  
  ```raku
  multi method unique()
  multi method unique( :&as!, :&with! )
  multi method unique( :&as! )
  multi method unique( :&with! )
  ```
  
  Creates a sequence of unique elements either of the object or of `values` in the case it's called as a `sub`.
  
  ```raku
  <1 2 2 3 3 3>.unique.say; # OUTPUT: «(1 2 3)␤»
  say unique <1 2 2 3 3 3>; # OUTPUT: «(1 2 3)␤»
  ```
  
  The `:as` and `:with` parameters receive functions that are used for transforming the item before checking equality, and for checking equality, since by default the [`===`](/routine/===) operator is used:
  
  ```raku
  ("1", 1, "1 ", 2).unique( as => Int, with => &[==] ).say; # OUTPUT: «(1 2)␤»
  ```
  
  Please see [`unique`](/type/independent-routines#routine_unique) for additional examples that use its sub form.
  
  # [In Independent routines](#___top "go to top of document")[§](#(Independent_routines)_routine_unique "direct link")
  
  See primary documentation
  [in context](/type/independent-routines#routine_unique)
  for **routine unique**.
  
  ```raku
  multi unique(+values, |c)
  ```
  
  Returns a sequence of **unique** values from the invocant/argument list, such that only the first occurrence of each duplicated value remains in the result list. `unique` uses the semantics of the [===](/routine/===) operator to decide whether two objects are the same, unless the optional `:with` parameter is specified with another comparator. The order of the original list is preserved even as duplicates are removed.
  
  Examples:
  
  ```raku
  say <a a b b b c c>.unique;   # OUTPUT: «(a b c)␤»
  say <a b b c c b a>.unique;   # OUTPUT: «(a b c)␤»
  ```
  
  (Use [squish](/routine/squish) instead if you know the input is sorted such that identical objects are adjacent.)
  
  The optional `:as` parameter allows you to normalize/canonicalize the elements before unique-ing. The values are transformed for the purposes of comparison, but it's still the original values that make it to the result list; however, only the first occurrence will show up in that list:
  
  Example:
  
  ```raku
  say <a A B b c b C>.unique(:as(&lc))      # OUTPUT: «(a B c)␤»
  ```
  
  One can also specify the comparator with the optional `:with` parameter. For instance if one wants a list of unique hashes, one could use the `eqv` comparator.
  
  Example:
  
  ```raku
  my @list = %(a => 42), %(b => 13), %(a => 42);
  say @list.unique(:with(&[eqv]))           # OUTPUT: «({a => 42} {b => 13})␤»
  ```
  
  **Note:** since `:with` [`Callable`](/type/Callable) has to be tried with all the items in the list, this makes `unique` follow a path with much higher algorithmic complexity. You should try to use the `:as` argument instead, whenever possible.
  
  # [In Supply](#___top "go to top of document")[§](#(Supply)_method_unique "direct link")
  
  See primary documentation
  [in context](/type/Supply#method_unique)
  for **method unique**.
  
  ```raku
  method unique(Supply:D: :$as, :$with, :$expires --> Supply:D)
  ```
  
  Creates a supply that only provides unique values, as defined by the optional `:as` and `:with` parameters (same as with [`unique`](/type/independent-routines#routine_unique)). The optional `:expires` parameter how long to wait (in seconds) before "resetting" and not considering a value to have been seen, even if it's the same as an old value.
  