MoonBit Language Tour MoonBit

Immutable Map

Similar to the immutable set, there are two immutable maps:

  • Hash map in the @immut/hashmap
  • Sorted map in the @immut/sorted_map

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

///|
fn main {
  let a = @immut/hashmap.of([(1, "a"), (2, "b"), (3, "c")])
  let b = a.add(4, "d")
  let c = @immut/sorted_map.from_iter(b.iter())
  println(c.keys())
}