FuncType - v0.60.3
    Preparing search index...

    Interface Obj<T>

    The Obj type wraps a plain JavaScript object and provides fluent, immutable operations for building and transforming objects.

    // Build HTTP headers immutably with conditional auth
    const headers = Obj({ "User-Agent": userAgent })
    .assign(options.headers)
    .when(requiresAuth, { Authorization: `Bearer ${token}` })
    .value()

    // Fluent object construction
    Obj.of({ name: "John" })
    .set("age", 31)
    .merge({ city: "NYC" })
    .value()
    interface Obj<T extends Record<string, Type>> {
        _tag: "Obj";
        "[toStringTag]": string;
        data: T;
        isEmpty: boolean;
        size: number;
        ap<U extends Record<string, unknown>>(
            ff: Obj<Record<string, unknown>>,
        ): Obj<U>;
        assign(partial: Partial<T>): Obj<T>;
        contains(value: unknown): boolean;
        count(p: (x: T) => boolean): number;
        doUnwrap(): DoResult<T>;
        entries(): List<Tuple<[string, T[keyof T]]>>;
        exists(p: (a: T) => boolean): boolean;
        find(p: (a: T) => boolean): Option<T>;
        flatMap<U extends Record<string, unknown>>(f: (value: T) => Obj<U>): Obj<U>;
        flatMapAsync<U extends Record<string, unknown>>(
            f: (value: T) => PromiseLike<Obj<U>>,
        ): PromiseLike<Obj<U>>;
        fold<U extends unknown>(onEmpty: () => U, onValue: (value: T) => U): U;
        foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B;
        foldRight<B>(z: B): (op: (a: T, b: B) => B) => B;
        forEach(f: (a: T) => void): void;
        get<K extends string | number | symbol>(key: K): Option<T[K]>;
        has<K extends string | number | symbol>(key: K): boolean;
        keys(): List<string>;
        map<U extends Record<string, unknown>>(f: (value: T) => U): Obj<U>;
        match<R>(patterns: Record<Tags, (value: A) => R>): R;
        merge<U extends Record<string, unknown>>(other: U): Obj<T & U>;
        omit<K extends string | number | symbol>(...keys: K[]): Obj<Omit<T, K>>;
        or<T2 extends unknown>(alternative: Extractable<T2>): Extractable<T | T2>;
        orElse<T2 extends unknown>(defaultValue: T2): T | T2;
        orNull(): T | null;
        orThrow(error?: Error): T;
        orUndefined(): T | undefined;
        pick<K extends string | number | symbol>(...keys: K[]): Obj<Pick<T, K>>;
        pipe<U extends unknown>(f: (value: T) => U): U;
        reduce<B = T>(
            op: (b: Widen<T, B>, a: Widen<T, B>) => Widen<T, B>,
        ): Widen<T, B>;
        reduceRight<B = T>(
            op: (b: Widen<T, B>, a: Widen<T, B>) => Widen<T, B>,
        ): Widen<T, B>;
        serialize(): SerializationMethods<T>;
        set<K extends string | number | symbol>(key: K, value: T[K]): Obj<T>;
        toEither<E extends unknown>(leftValue: E): Either<E, T>;
        toList(): List<T>;
        toOption(): Option<T>;
        toPromise(): Promise<T>;
        toString(): string;
        toTry(): Try<T>;
        toValue(): { _tag: "Obj"; value: T };
        value(): T;
        values(): List<T[keyof T]>;
        when(condition: boolean | (() => boolean), partial: Partial<T>): Obj<T>;
    }

    Type Parameters

    • T extends Record<string, Type>

      The record type of the contained object

    Hierarchy (View Summary)

    Index

    Properties

    _tag: "Obj"
    "[toStringTag]": string
    data: T

    The contained object value

    isEmpty: boolean
    size: number

    Methods

    • Applies a wrapped function to the contained object

      Type Parameters

      • U extends Record<string, unknown>

      Parameters

      • ff: Obj<Record<string, unknown>>

        An Obj containing a function from T to U

      Returns Obj<U>

      A new Obj containing the result

    • Merge a partial of the same shape (no new keys)

      Parameters

      • partial: Partial<T>

        Partial object to merge

      Returns Obj<T>

      A new Obj with merged values

    • Parameters

      • value: unknown

      Returns boolean

    • Counts elements that satisfy the predicate. For single-value containers: returns 0 or 1 For collections: returns the count of matching elements

      Parameters

      • p: (x: T) => boolean

      Returns number

    • Return a List of [key, value] Tuples

      Returns List<Tuple<[string, T[keyof T]]>>

      List of key-value Tuples

    • Tests whether any element satisfies the predicate. For single-value containers: tests the single value For collections: returns true if any element matches

      Parameters

      • p: (a: T) => boolean

      Returns boolean

    • Finds the first element that satisfies the predicate. For single-value containers: returns Some(value) if predicate matches, None otherwise For collections: returns the first matching element wrapped in Option

      Parameters

      • p: (a: T) => boolean

      Returns Option<T>

    • FlatMaps the contained object using a function that returns an Obj

      Type Parameters

      • U extends Record<string, unknown>

      Parameters

      • f: (value: T) => Obj<U>

        The flatMap function

      Returns Obj<U>

      The Obj returned by f

    • Async flatMap for the contained object

      Type Parameters

      • U extends Record<string, unknown>

      Parameters

      • f: (value: T) => PromiseLike<Obj<U>>

        The async flatMap function

      Returns PromiseLike<Obj<U>>

      A Promise of the Obj returned by f

    • Pattern match fold — applies onEmpty if empty, onValue if non-empty

      Type Parameters

      • U extends unknown

      Parameters

      • onEmpty: () => U

        Handler for empty Obj

      • onValue: (value: T) => U

        Handler for non-empty Obj

      Returns U

      The result of the matching handler

    • Left-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (b: B, a: T) => B) => B

      A function that takes an operation to apply

    • Right-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (a: T, b: B) => B) => B

      A function that takes an operation to apply

    • Applies an effect function to each element. For single-value containers: applies to the value if present For collections: applies to each element

      Parameters

      • f: (a: T) => void

      Returns void

    • Get a value by key, returning Option

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • key: K

        The key to look up

      Returns Option<T[K]>

      Option containing the value if present

    • Check if a key exists

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • key: K

        The key to check

      Returns boolean

      true if the key exists

    • Return a List of keys

      Returns List<string>

      List of string keys

    • Maps the contained object to a new object using the provided function

      Type Parameters

      • U extends Record<string, unknown>

      Parameters

      • f: (value: T) => U

        The mapping function (must return a Record)

      Returns Obj<U>

      A new Obj containing the mapped value

    • Pattern matches against this data structure, applying handlers for each variant based on tag. Similar to fold but with stronger type safety for tag-based variants.

      The return type is inferred from the pattern handlers when not explicitly specified.

      Type Parameters

      • R

      Parameters

      • patterns: Record<Tags, (value: A) => R>

        An object containing handler functions for each variant

      Returns R

      The result of applying the matching handler function

    • Merge with a potentially wider type (can add new keys)

      Type Parameters

      • U extends Record<string, unknown>

      Parameters

      • other: U

        Object to merge in

      Returns Obj<T & U>

      A new Obj with the merged type

    • Return a new Obj without the specified keys

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • ...keys: K[]

        Keys to remove

      Returns Obj<Omit<T, K>>

      A new Obj without the specified keys

    • Returns this container if it has a value, otherwise returns the alternative container. The alternative may carry a different type; the result widens to Extractable<T | T2>.

      Type Parameters

      • T2 extends unknown

      Parameters

      Returns Extractable<T | T2>

      This container or the alternative

    • Returns the contained value or a default value. The default may be of a different type; the result widens to T | T2.

      Type Parameters

      • T2 extends unknown

      Parameters

      • defaultValue: T2

        The value to return if extraction fails

      Returns T | T2

      The contained value or defaultValue

    • Returns the contained value or null

      Returns T | null

      The contained value or null

    • Extract the value or throw an error

      Parameters

      • Optionalerror: Error

        Optional custom error to throw. If not provided, uses type-appropriate default error

      Returns T

      The contained value

      The specified error, container's error, or a sensible default

    • Returns the contained value or undefined

      Returns T | undefined

      The contained value or undefined

    • Return a new Obj with only the specified keys

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • ...keys: K[]

        Keys to keep

      Returns Obj<Pick<T, K>>

      A new Obj with only the specified keys

    • Pipes the value through the provided function

      Type Parameters

      • U extends unknown

        The return type of the function

      Parameters

      • f: (value: T) => U

        The function to apply to the value

      Returns U

      The result of applying the function to the value

    • Set a single key to a new value, returning a new Obj

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • key: K

        The key to set (must exist in T)

      • value: T[K]

        The value to set

      Returns Obj<T>

      A new Obj with the updated key

    • Converts this monad to an Either.

      Conversion rules:

      • Option: Some → Right, None → Left(leftValue)
      • Either: returns self
      • List: non-empty → Right(head), empty → Left(leftValue)
      • Try: Success → Right, Failure → Left(error)

      Type Parameters

      • E extends unknown

      Parameters

      • leftValue: E

        The value to use for the Left case when the source is empty/none/failure

      Returns Either<E, T>

      An Either with the value as Right or the provided leftValue as Left

    • Converts this monad to a List.

      Conversion rules:

      • Option: Some → List([value]), None → List([])
      • Either: Right → List([value]), Left → List([])
      • List: returns self
      • Try: Success → List([value]), Failure → List([])

      Returns List<T>

      A List containing the value(s) if present, empty List otherwise

    • Converts this monad to an Option.

      Conversion rules:

      • Option: returns self
      • Either: Right → Some, Left → None
      • List: non-empty → Some(head), empty → None
      • Try: Success → Some, Failure → None

      Returns Option<T>

      An Option containing the value if present, None otherwise

    • Converts this container to a Promise

      The behavior depends on the implementing container:

      • Success/Right/Some containers resolve with their value
      • Failure/Left/None containers reject with their error/default error

      Returns Promise<T>

      A Promise that resolves or rejects based on the container's state

    • Returns a string representation of this Obj

      Returns string

      A string representation

    • Converts this monad to a Try.

      Conversion rules:

      • Option: Some → Success, None → Failure(Error("None"))
      • Either: Right → Success, Left → Failure(Error(leftValue))
      • List: non-empty → Success(head), empty → Failure(Error("Empty list"))
      • Try: returns self

      Returns Try<T>

      A Try containing Success with the value or Failure with an appropriate error

    • Returns { _tag: "Obj"; value: T }

    • Unwrap to the plain object

      Returns T

      The contained plain object

    • Return a List of values

      Returns List<T[keyof T]>

      List of values

    • Conditionally merge a partial based on a boolean or predicate

      Parameters

      • condition: boolean | (() => boolean)

        Boolean or predicate function

      • partial: Partial<T>

        Partial to merge if condition is true

      Returns Obj<T>

      A new Obj, with or without the merge applied