Data & text · BUILT-IN MODULE

collections

List, Map, Set, sorting, mapping, and filtering helpers.

Quick start

use collections
use collections

nums = [3, 1, 3, 2]
say collections.sort nums
say collections.unique nums
say collections.first nums

API reference

collections.reverse values

Reverse a collection.

反轉集合。
collections.contains values value

Check membership.

檢查成員是否存在。
collections.first values

Return the first value.

回傳第一個值。
collections.last values

Return the last value.

回傳最後一個值。
collections.unique values

Remove duplicate values.

移除重複值。
collections.sort values

Sort values.

排序值。
collections.keys map

Return Map keys.

回傳 Map 的 keys。
collections.values map

Return Map values.

回傳 Map 的 values。
collections.filter list predicate

Return values for which predicate is true.

回傳 values for which predicate is true.
collections.map list function

Transform every value into a new List.

Transform every value into a new List.
collections.reduce list initial function

Reduce a List into one value.

歸約 a List into one value.
collections.slice list start end

Return a List slice.

回傳 a List slice.
collections.take list count

Take the first count values.

Take the first count values.
collections.drop list count

Drop the first count values.

Drop the first count values.
collections.sort_by list field

Sort by a field/key.

排序 by a field/key.
collections.sort_by_desc list field

Sort descending by field/key.

排序 descending by field/key.
collections.sort_with list comparator

Sort using a comparator function.

排序 using a comparator function.