Record
Functions
Section titled “Functions”lookup
Section titled “lookup”Safely lookup a value in a Record by key, returning an Option.
Examples
Section titled “Examples”Data first style
import { Record, Option } from "@jvlk/fp-tsm"import { expect } from "jsr:@std/expect"
type T = { a: number | undefined; b: number | null; c?: number }
const record: T = { a: 1, b: null }
const a: Option.Option<number> = Record.lookup(record, "a")const b: Option.Option<number> = Record.lookup(record, "b")const c: Option.Option<number> = Record.lookup(record, "c")
expect(a).toEqual(Option.of(1))expect(b).toEqual(Option.none)expect(c).toEqual(Option.none)
Pipe style
import { Record, Option, pipe } from "@jvlk/fp-tsm"import { expect } from "jsr:@std/expect"
type T = { a: number | undefined; b: number | null; c?: number }
const record: T = { a: 1, b: null }
const a: Option.Option<number> = pipe(record, Record.lookup("a"))const b: Option.Option<number> = Record.lookup(record, "b")const c: Option.Option<number> = Record.lookup(record, "c")
expect(a).toEqual(Option.of(1))expect(b).toEqual(Option.none)expect(c).toEqual(Option.none)