Home / Class/ Both Class — supabase Architecture

Both Class — supabase Architecture

Architecture documentation for the Both class in helpers.fn.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/docs/features/helpers.fn.ts lines 188–230

export class Both<Left, Right> {
  private internal: {
    left: Left
    right: Right
  }

  constructor(left: Left, right: Right) {
    this.internal = {
      left,
      right,
    }
  }

  mapLeft<NewLeft>(fn: (left: Left) => NewLeft): Both<NewLeft, Right> {
    return new Both(fn(this.internal.left), this.internal.right)
  }

  mapRight<NewRight>(fn: (right: Right) => NewRight): Both<Left, NewRight> {
    return new Both(this.internal.left, fn(this.internal.right))
  }

  async mapLeftAsync<NewLeft>(fn: (left: Left) => Promise<NewLeft>): Promise<Both<NewLeft, Right>> {
    const res = await fn(this.internal.left)
    return new Both(res, this.internal.right)
  }

  unwrapLeft(): Left {
    return this.internal.left
  }

  unwrapRight(): Right {
    return this.internal.right
  }

  combine<Output>(fn: (left: Left, right: Right) => Output): Output {
    return fn(this.internal.left, this.internal.right)
  }

  intoResult(): Result<Left, Right> {
    if (this.internal.right) return Result.error(this.internal.right)
    return Result.ok(this.internal.left)
  }
}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free