class std::ListExt

sys::Obj
  std::ListExt
findType

static extension List<Obj?> findType(List<Obj?> self, Type t)

Return a new list containing all the items which are an instance of the specified type such that item.type.fits(t) is true. Any null items are automatically excluded. If none of the items are instance of the specified type, then an empty list is returned. The returned list will be a list of t. This method is readonly safe.

Example:

list := ["a", 3, "foo", 5sec, null]
list.findType(Str#) => Str["a", "foo"]
groupBy

static extension Map<Obj,List<Obj?>> groupBy(List<Obj?> self, Func<Obj,Obj?,Int> c)

Group items into buckets keyed by the given function. The result is a map of lists where the map keys are generated by the given function. The map values are the items which share the same key. The resulting map key type is determined by the return type of c.

Example:

// group by string size
list := ["ape", "bear", "cat", "deer"]
list.groupBy |s->Int| { s.size }  =>  [3:[ape, cat], 4:[bear, deer]]
groupByInto

static extension Map<Obj,List<Obj?>> groupByInto(List<Obj?> self, Map<Obj,List<Obj?>> map, Func<Obj,Obj?,Int> c)

Group by into an existing map. This method shares the same semantics as groupBy except it adds into the given map.

intersection

static extension List<Obj?> intersection(List<Obj?> self, List<Obj?> that)

Return a new list which is the intersection of this list and the given list. The intersection is defined as the unique items which are in both lists. The new list will be ordered according to this list's order. The new list is guaranteed to be unique with no duplicate values. Equality is determined using hash() and the == operator (shortcut for equals method). This method is readonly safe.

Example:

[0, 1, 2, 3].intersection([5, 3, 1]) => [1, 3]
[0, null, 2].intersection([null, 0, 1, 2, 3]) => [0, null, 2]
union

static extension List<Obj?> union(List<Obj?> self, List<Obj?> that)

Return a new list which is the union of this list and the given list. The union is defined as the unique items which are in either list. The resulting list is ordered first by this list's order, and secondarily by that's order. The new list is guaranteed to be unique with no duplicate values. Equality is determined using hash() and the == operator (shortcut for equals method). This method is readonly safe.

Example:

[1, 2].union([3, 2]) => [1, 2, 3]
unique

static extension List<Obj?> unique(List<Obj?> self)

Returns a new list with all duplicate items removed such that the resulting list is a proper set. Duplicates are detected using hash() and the == operator (shortcut for equals method). This method is readonly safe.

Example:

["a", "a", "b", "c", "b", "b"].unique => ["a", "b", "c"]