Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #363 Set to list

Create the list y from the set x.

The resulting list y may be in any order.

y := make([]T, 0, len(x))
for v := range x {
	y = append(y, v)
}
import "maps"
import "slices"
y := slices.Collect(maps.Keys(x))
fgl
Type
  TSet = set of T;
  TList = specialize TFPGList<T>;
var
  x: TSet;
  y: TList;
  item: T;
begin
...
  y := TList.Create;
  for item in x do y.Add(item);
...
y = list(x)
y = x.to_a

New implementation...
< >
programming-idioms.org