This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Clojure
- C++
- C++
- C#
- D
- D
- Dart
- Elixir
- Elixir
- Erlang
- Go
- Go
- Haskell
- JS
- Java
- Java
- Java
- Java
- Java
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Perl
- Python
- Python
- Ruby
- Rust
- Scala
- Smalltalk
y = x |> Enum.uniq |> List.to_tuple
Remove list duplication and convert to a tuple.
Warning: a tuple is not really a set.
Warning: a tuple is not really a set.
func sliceToSet[T comparable](x []T) map[T]struct{} {
y := make(map[T]struct{}, len(x))
for _, v := range x {
y[v] = struct{}{}
}
return y
}
sliceToSet is generic. Its type parameter T has a constraint: must be comparable with ==.
y := make(map[T]struct{}, len(x))
for _, v := range x {
y[v] = struct{}{}
}
Iterate to add each item to the map.
T is the type of the items.
T is the type of the items.
Set<T> y = x.stream().collect(toSet());
Set<T> y = new HashSet<>(x);
T is the type of the elements.
Set<T> y = new LinkedHashSet<>(x);
The `LinkedHashSet` will preserve the order of x.
local hash = {}
local y = {}
for _,v in ipairs(x) do
if (not hash[v]) then
y[#y+1] = v
hash[v] = true
end
end
my @y = uniq @x;
Filters a list of values to remove subsequent duplicates. Preserves the order of unique elements, and retains the first value of any duplicate set.
programming-idioms.org