Skip to content

Function: map()

WARNING

This API is experimental and may change in future versions.

Transform the output of a combinator schema.

Creates a new schema that applies transform to the result of schema.parse. The original schema is not modified.

Signature

ts
declare function map<T, U>(schema: CombinatorSchema<T>, transform: (value: T) => U): CombinatorSchema<U>

Type Parameters

NameDescription
TThe input schema's parsed type.
UThe transformed type.

Parameters

NameTypeDescription
schemaCombinatorSchema<T>The base combinator schema.
transform(value: T) => UThe transformation function.

Returns

CombinatorSchema<U> — A new combinator schema that resolves to the transformed type.

Examples

ts
const args = {
  doubled: map(integer(), n => n * 2)
}

Released under the MIT License.