Skip to content

OrderlyMap

youyihj edited this page Apr 16, 2023 · 1 revision

OrderlyMap

@since 1.13.0

The orderly map is a special associative array with predictable iteration order.

Add $orderly suffix in map type declaration to call an orderly map.

// plain map
val map as string[string] = {
    "test": "abc",
    "foo": "bar",
    "mine": "craft"
};

for key, value in map {
    print(key ~ ": " ~ value);
}

/* results:
[INITIALIZATION][CLIENT][INFO] mine: craft
[INITIALIZATION][CLIENT][INFO] test: abc
[INITIALIZATION][CLIENT][INFO] foo: bar
*/

// orderly map
val orderlyMap as string[string]$orderly = {
    "test": "abc",
    "foo": "bar",
    "mine": "craft"
};

for key, value in orderlyMap {
    print(key ~ ": " ~ value);
}

/* results:
[INITIALIZATION][CLIENT][INFO] test: abc
[INITIALIZATION][CLIENT][INFO] foo: bar
[INITIALIZATION][CLIENT][INFO] mine: craft
*/
Clone this wiki locally