Hyperlinkv0.8.0-beta.28

Struct

Struct.pickconsteffect/Struct.ts:197
<S extends object, const Keys extends ReadonlyArray<keyof S>>(
  keys: Keys
): (self: S) => Simplify<Pick<S, Keys[number]>>
<S extends object, const Keys extends ReadonlyArray<keyof S>>(
  self: S,
  keys: Keys
): Simplify<Pick<S, Keys[number]>>

Creates a new struct containing only the specified keys.

When to use

Use to narrow a struct down to a subset of its properties.

Gotchas

Keys not present in the struct are silently ignored.

Example (Selecting specific properties)

import { pipe, Struct } from "effect"

const user = { name: "Alice", age: 30, admin: true }
const nameAndAge = pipe(user, Struct.pick(["name", "age"]))
console.log(nameAndAge) // { name: "Alice", age: 30 }
filteringomitget
Source effect/Struct.ts:19711 lines
export const pick: {
  <S extends object, const Keys extends ReadonlyArray<keyof S>>(
    keys: Keys
  ): (self: S) => Simplify<Pick<S, Keys[number]>>
  <S extends object, const Keys extends ReadonlyArray<keyof S>>(self: S, keys: Keys): Simplify<Pick<S, Keys[number]>>
} = dual(
  2,
  <S extends object, const Keys extends ReadonlyArray<keyof S>>(self: S, keys: Keys) => {
    return buildStruct(self, (k, v) => (keys.includes(k) ? [k, v] : undefined))
  }
)