Constraints
Comparable
Section titled “Comparable”Equivalent to Go’s comparable. Satisfied by every type that admits
== and !=.
fn unique<T: Comparable>(items: Slice<T>) -> Map<T, bool> { let mut seen = Map.new<T, bool>() for item in items { seen[item] = true } seen}
let numbers = unique([1, 2, 2, 3]).length()3let words = unique(["a", "b", "a"]).length()2Ordered
Section titled “Ordered”Equivalent to Go’s cmp.Ordered. Satisfied by every type that admits
<, <=, >= and >.
fn descending<T: Ordered>(a: T, b: T) -> (T, T) { if a > b { (a, b) } else { (b, a) }}
let numbers = descending(3, 7)(7, 3)let words = descending("pear", "apple")("pear", "apple")