pluck
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]
.
Example
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 ] }
Since
3.10.0
Call Signature
pluck<
A
,I
,K
>(key
): <R
>(schema
) =>SchemaClass
<A
[K
], { [K in string | number | symbol]: Pick<I, K>[K] },R
>
Defined in: node_modules/.pnpm/effect@3.14.8/node_modules/effect/dist/dts/Schema.d.ts:1528
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]
.
Type Parameters
• A
• I
• K extends string
| number
| symbol
Parameters
key
K
Returns
Function
Type Parameters
• R
Parameters
schema
Schema
<A
, I
, R
>
Returns
SchemaClass
<A
[K
], { [K in string | number | symbol]: Pick<I, K>[K] }, R
>
Examples
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 ] }
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 ] }
Since
3.10.0
Since
3.10.0
Call Signature
pluck<
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.14.8/node_modules/effect/dist/dts/Schema.d.ts:1559
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]
.
Type Parameters
• A
• I
• R
• K extends string
| number
| symbol
Parameters
schema
Schema
<A
, I
, R
>
key
K
Returns
SchemaClass
<A
[K
], { [K in string | number | symbol]: Pick<I, K>[K] }, R
>
Examples
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 ] }
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 ] }
Since
3.10.0
Since
3.10.0