MoonBit Language Tour MoonBit

Immutable Set

The immutable set has two variants:

  • Hash set in the @immut/hashset
  • Sorted set in the @immut/sorted_set

The first one is hash based and hence unordered while the second one require its key to be ordered.

///|
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)
}