MoonBit 语言导览 MoonBit

不可变集合

不可变集合有两种实现:

  • @immut/hashset 中的哈希集合
  • @immut/sorted_set 中的排序集合

因此,它们的行为不同,API 也不同。

///|
fn main {
  let a = @immut/hashset.of([5, 4, 3, 2, 1])
  let b = @immut/sorted_set.of([5, 4, 3, 2, 1])
  let arraya = a.iter().collect()
  let arrayb = b.iter().collect()
  let c = a.add(6)
  let d = b.add(6)
  let except_one = d.remove_min()
  println(d)
}