Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "join"

Index

Functions

Functions

Const join

  • join<A, B>(a: Set<A>, b: Set<B>): Set<Pick<A, keyof A> & Pick<B, keyof B>>
  • Computes the natural join between the two sets of relations. Each set is assumed to have plain objects as values with at least one of the keys present in both sides. Furthermore the objects in each set are assumed to have the same internal structure (i.e. sets of keys). Returns new set of same type as a.

    example
    join(
      new Set([
        {id: 1, name: "foo"},
        {id: 2, name: "bar"},
        {id: 3, name: "baz"}]),
      new Set([
        {id: 1, color: "red"},
        {id: 2, color: "blue"}])
    )
    // Set {
    //   { id: 1, color: 'red', name: 'foo' },
    //   { id: 2, color: 'blue', name: 'bar' }
    // }

    Type parameters

    • A

    • B

    Parameters

    • a: Set<A>

      first set

    • b: Set<B>

      other set

    Returns Set<Pick<A, keyof A> & Pick<B, keyof B>>

Const joinWith

  • joinWith<A, B>(a: Set<A>, b: Set<B>, kmap: {}): Set<any>
  • Similar to join, computes the join between two sets of relations, using the given keys in kmap only for joining and ignoring others. kmap can also be used to translate join keys in b where needed. Else, if no renaming is desired, the values in kmap should be the same as their respective keys, e.g. {id: "id"}. Returns new set of same type as a.

    example
    joinWith(
      new Set([
        {id: 1, name: "foo"},
        {id: 2, name: "bar"},
        {id: 3, name: "baz"}]),
      new Set([
        {type: 1, color: "red"},
        {type: 2, color: "blue"}]),
      {id: "type"}
    )
    // Set {
    //   { type: 1, color: 'red', id: 1, name: 'foo' },
    //   { type: 2, color: 'blue', id: 2, name: 'bar' } }

    Type parameters

    • A

    • B

    Parameters

    • a: Set<A>

      first set

    • b: Set<B>

      other set

    • kmap: {}

      keys to compute join for

      Returns Set<any>

    Generated using TypeDoc