Skip to content

pluck

const pluck: {<A, I, K>(key): <R>(schema) => SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>; <A, I, R, K>(schema, key): SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>; }

Defined in: node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/dts/Schema.d.ts:1497

Given a schema Schema<A, I, R> and a key key: K, this function extracts a specific field from the A type, producing a new schema that represents a transformation from the { readonly [key]: I[K] } type to A[K].

<A, I, K>(key): <R>(schema) => SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>

Given a schema Schema<A, I, R> and a key key: K, this function extracts a specific field from the A type, producing a new schema that represents a transformation from the { readonly [key]: I[K] } type to A[K].

A

I

K extends string | number | symbol

K

<R>(schema): SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>

R

Schema<A, I, R>

SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>

import * as Schema from "effect/Schema"
// ---------------------------------------------
// use case: pull out a single field from a
// struct through a transformation
// ---------------------------------------------
const mytable = Schema.Struct({
column1: Schema.NumberFromString,
column2: Schema.Number
})
// const pullOutColumn: S.Schema<number, {
// readonly column1: string;
// }, never>
const pullOutColumn = mytable.pipe(Schema.pluck("column1"))
console.log(Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([{ column1: "1", column2: 100 }, { column1: "2", column2: 300 }]))
// Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] }

3.10.0

<A, I, R, K>(schema, key): SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>

Given a schema Schema<A, I, R> and a key key: K, this function extracts a specific field from the A type, producing a new schema that represents a transformation from the { readonly [key]: I[K] } type to A[K].

A

I

R

K extends string | number | symbol

Schema<A, I, R>

K

SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>

import * as Schema from "effect/Schema"
// ---------------------------------------------
// use case: pull out a single field from a
// struct through a transformation
// ---------------------------------------------
const mytable = Schema.Struct({
column1: Schema.NumberFromString,
column2: Schema.Number
})
// const pullOutColumn: S.Schema<number, {
// readonly column1: string;
// }, never>
const pullOutColumn = mytable.pipe(Schema.pluck("column1"))
console.log(Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([{ column1: "1", column2: 100 }, { column1: "2", column2: 300 }]))
// Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] }

3.10.0

import * as Schema from "effect/Schema"
// ---------------------------------------------
// use case: pull out a single field from a
// struct through a transformation
// ---------------------------------------------
const mytable = Schema.Struct({
column1: Schema.NumberFromString,
column2: Schema.Number
})
// const pullOutColumn: S.Schema<number, {
// readonly column1: string;
// }, never>
const pullOutColumn = mytable.pipe(Schema.pluck("column1"))
console.log(Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([{ column1: "1", column2: 100 }, { column1: "2", column2: 300 }]))
// Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] }

3.10.0