packagestdlibimport"list"l1: [1, 2, 3, 4, 5]l2: ["c", "b", "a"]// constrain lengthl2: list.MinItems(1)l2: list.MaxItems(3)// slice a listl3: list.Slice(l1, 2, 4)// get the sum and productsum: list.Sum(l1)prd: list.Product(l1)// linear search for list (no binary)lc: list.Contains(l1, 2)// sort a listls: list.Sort(l2, list.Ascending)l2s: list.IsSorted(l2, list.Ascending)lss: list.IsSorted(ls, list.Ascending)// Flatten a listll: [1, [2, 3], [4, [5]]]lf: list.FlattenN(ll, 1)
Constrain
constrain.cue
packagestdlibimport ("net""time")// string with ip formatip: net.IPv4ip: "10.1.2.3"// string with time formatts: time.Format(time.ANSIC)ts: "Mon Jan 2 15:04:05 2006"