Hyperlinkv0.8.0-beta.28

Record

Record.popconsteffect/Record.ts:584
<K extends string | symbol, X extends K>(key: X): <A>(
  self: ReadonlyRecord<K, A>
) => Option.Option<[A, Record<Exclude<K, X>, A>]>
<K extends string | symbol, A, X extends K>(
  self: ReadonlyRecord<K, A>,
  key: X
): Option.Option<[A, Record<Exclude<K, X>, A>]>

Retrieves the value of the property with the given key from a record safely and returns an Option of a tuple with the value and the record with the removed property. If the key is not present, returns Option.none().

Example (Popping a value and removing its key)

import { Record } from "effect"

const input: Record<string, number> = { a: 1, b: 2 }

Record.pop(input, "a") // Option.some([1, { b: 2 }])
Record.pop(input, "c") // Option.none()
mutations
Source effect/Record.ts:58413 lines
export const pop: {
  <K extends string | symbol, X extends K>(
    key: X
  ): <A>(self: ReadonlyRecord<K, A>) => Option.Option<[A, Record<Exclude<K, X>, A>]>
  <K extends string | symbol, A, X extends K>(
    self: ReadonlyRecord<K, A>,
    key: X
  ): Option.Option<[A, Record<Exclude<K, X>, A>]>
} = dual(2, <K extends string | symbol, A, X extends K>(
  self: ReadonlyRecord<K, A>,
  key: X
): Option.Option<[A, Record<Exclude<K, X>, A>]> =>
  has(self, key) ? Option.some([self[key], remove(self, key)]) : Option.none())