Hyperlinkv0.8.0-beta.28

Record

Record.removeconsteffect/Record.ts:550
<K extends string | symbol, X extends K>(key: X): <A>(
  self: ReadonlyRecord<K, A>
) => Record<Exclude<K, X>, A>
<K extends string | symbol, A, X extends K>(
  self: ReadonlyRecord<K, A>,
  key: X
): Record<Exclude<K, X>, A>

Removes a key from a record.

When to use

Use to create a shallow copy of a record without one property.

Details

If the key is not present, the result is still a shallow copy of the original record.

Example (Removing a key)

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

assert.deepStrictEqual(Record.remove({ a: 1, b: 2 }, "a"), { b: 2 })
mutations
Source effect/Record.ts:55014 lines
export const remove: {
  <K extends string | symbol, X extends K>(key: X): <A>(self: ReadonlyRecord<K, A>) => Record<Exclude<K, X>, A>
  <K extends string | symbol, A, X extends K>(self: ReadonlyRecord<K, A>, key: X): Record<Exclude<K, X>, A>
} = dual(
  2,
  <K extends string | symbol, A, X extends K>(self: ReadonlyRecord<K, A>, key: X): Record<Exclude<K, X>, A> => {
    if (!has(self, key)) {
      return { ...self }
    }
    const out = { ...self }
    delete out[key]
    return out
  }
)
Referenced by 1 symbols