Skip to content

gunshi / combinators / map

Function: map()

ts
function map<T, U>(schema, transform): CombinatorSchema<U>;

Experimental

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.

Type Parameters

Type ParameterDescription
TThe input schema's parsed type.
UThe transformed type.

Parameters

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

Returns

CombinatorSchema<U>

A new combinator schema that resolves to the transformed type.

Example

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

Released under the MIT License.