Skip to main content

Dict

import { Dict } from "@swan-io/boxed";

Dict.entries(dict)

Returns the entries in the dict.

Contrary to the TS bindings for Object.entries, the types are refined.

Examples
const index = Dict.entries({ foo: 1, bar: 2, baz: 3 });
// [["foo", 1], ["bar", 2], ["baz", 3]];

Dict.keys(dict)

Returns the keys in the dict.

Contrary to the TS bindings for Object.keys, the types are refined.

Examples
const index = Dict.keys({ foo: 1, bar: 2, baz: 3 });
// ["foo", "bar", "baz"];

Dict.values(dict)

Returns the values in the dict.

Contrary to the TS bindings for Object.values, the types are refined.

Examples
const index = Dict.values({ foo: 1, bar: 2, baz: 3 });
// [1, 2, 3];

Dict.fromOptional(dictOfOptions)

Takes a dict whose values are Option<unknown> and returns a dict containing only the values contained in Some.

Examples
Dict.fromOptional({
foo: Option.Some(1),
bar: Option.None(),
baz: Option.None(),
});
// {foo: 1}

Dict.fromOptional({
foo: Option.Some(1),
bar: Option.Some(2),
baz: Option.None(),
});
// {foo: 1, bar: 2}

Dict.fromOptional({
foo: Option.None(),
bar: Option.None(),
baz: Option.None(),
});
// {}