Module std/record.vv
The record module provides utilities for working with records (key-value maps).
Records are unordered collections of fields, where keys are typically strings or integers.
Example:
import record from "std/record.vv"
let r = { a = 1, b = 2 }
record.set(r, "c", 3)
let keys = record.keys(r)
Exports
fun get(r, k)
extern "native"
Gets the value associated with the given key in a record.
Returns none if the key does not exist.
Example:
let r = { a = 1 }
let v = record.get(r, "a") // 1
let e = record.get(r, "b") // none
fun set(r, k, v)
extern "native"
Sets the value for the given key in a record, modifying it in place. Returns the modified record.
Example:
let r = {}
record.set(r, "a", 1) // { a = 1 }
fun to_list(r)
extern "native"
Converts a record to a list of key-value pairs (each pair is a list of [key, value]).
Example:
let r = {a: 1, b: 2}
let l = record.to_list(r) // [["a", 1], ["b", 2]]
fun keys(r)
Returns a list of all keys in the record.
Example:
let r = {a: 1, b: 2}
let ks = record.keys(r) // ["a", "b"]
fun values(r)
Returns a list of all values in the record.
Example:
let r = {a: 1, b: 2}
let vs = record.values(r) // [1, 2]
fun has(r, k)
Checks if the record contains the specified key.
Example:
let r = {foo: "bar"}
let b1 = record.has(r, "foo") // true
let b2 = record.has(r, "baz") // false