Quick actions

cmd+k|ctrl+k

Navigation

Languages

nested table with []

Snippet info

Language

Nim

Visibility

unlisted

Author

legacy-anonymous

Created

2018-10-05T05:18:20Z

Updated

2018-10-05T05:18:20Z

import tables

type
  InnerTable = Table[string, string]
  NestedTable = Table[int, InnerTable]

func newNestedTable(): NestedTable = initTable[int, InnerTable]()
  
func newEmptyInnerTable(): InnerTable = initTable[string, string]()

func `[]`(self: var NestedTable, key: int): var InnerTable =
  self.mgetOrPut(key, newEmptyInnerTable())

var
  nestT = newNestedTable()

nestT[0]["a"] = "b"

echo nestT
INFO