Record module

The Record module contains functions for working with records in a dynamic manner.

getMembers

Signature: (record: {}) -> { label: text, value: unknown }*

Converts the record into a sequence of label/value pairs.

let user = {id: 0, name: "Bilal"}

return Record.getMembers(user);

fromMembers

Signature: (members: {label: text, value: unknown}*) -> {}

Converts a sequence of label/value pairs into a record. The type of the record will be empty. To work with the members using dot notation, you can use type narrowing.

let members = [
    { label: "id", value: "0" },
    { label: "name", value: "Bilal" }
];

return Record.fromMembers(members); // returns {id: 0, name: "Bilal"}

fromFunction

Signature: (f: (label: text) -> unknown) -> T

Creates a record based on a type and a function.

type User = {id: number, name: text}

let data = [
    { label: "id", value: 0 },
    { label: "name", value: "Bilal" },
]

return Record.fromFunction<User>(l => first(data where label = l).value);

Last updated