import std/tables type Foo = object Bar = distinct Table[string, Foo] proc `[]`(bar: Bar, key: string): Foo = Table[string, Foo](bar)[key] proc initTable(values: seq[tuple[key: string, value: Foo]]): Bar = var table = initTable[string, Foo]() for value in values: table[value.key] = value.value result = table.Bar var b = initTable(@[("la", Foo()), ("le", Foo()), ("li", Foo())]) # Bam, read only, no manipulation possible unless you cast back explicitly from # the distinct