Hyperlinkv0.8.0-beta.28

Record

Record.fromIterableByconsteffect/Record.ts:283
<A, K extends string | symbol>(
  items: Iterable<A>,
  f: (a: A) => K
): Record<ReadonlyRecord.NonLiteralKey<K>, A>

Creates a new record from an iterable, utilizing the provided function to determine the key for each element.

Example (Building a record keyed by iterable values)

import { Record } from "effect"
import * as assert from "node:assert"

const users = [
  { id: "2", name: "name2" },
  { id: "1", name: "name1" }
]

assert.deepStrictEqual(
  Record.fromIterableBy(users, (user) => user.id),
  {
    "2": { id: "2", name: "name2" },
    "1": { id: "1", name: "name1" }
  }
)
constructors
Source effect/Record.ts:2834 lines
export const fromIterableBy = <A, K extends string | symbol>(
  items: Iterable<A>,
  f: (a: A) => K
): Record<ReadonlyRecord.NonLiteralKey<K>, A> => fromIterableWith(items, (a) => [f(a), a])