Skip to content

@unthrown/pattern


@unthrown/pattern

Functions

defect()

Call Signature

ts
function defect(): object;

Defined in: index.ts:60

A ts-pattern pattern matching the Defect variant of a Result. With no argument it matches any Defect; pass a sub-pattern to constrain or select the unknown cause.

Returns

object

NameTypeDefined in
tag"Defect"index.ts:60

Call Signature

ts
function defect<V>(cause): object;

Defined in: index.ts:61

A ts-pattern pattern matching the Defect variant of a Result. With no argument it matches any Defect; pass a sub-pattern to constrain or select the unknown cause.

Type Parameters
Type ParameterDescription
Vthe sub-pattern matched against the Defect cause.
Parameters
ParameterType
causeV
Returns

object

NameTypeDefined in
causeVindex.ts:61
tag"Defect"index.ts:61

err()

Call Signature

ts
function err(): object;

Defined in: index.ts:47

A ts-pattern pattern matching the Err variant of a Result. With no argument it matches any Err; pass a sub-pattern (e.g. tag) to constrain or select the error.

Returns

object

NameTypeDefined in
tag"Err"index.ts:47

Call Signature

ts
function err<V>(error): object;

Defined in: index.ts:48

A ts-pattern pattern matching the Err variant of a Result. With no argument it matches any Err; pass a sub-pattern (e.g. tag) to constrain or select the error.

Type Parameters
Type ParameterDescription
Vthe sub-pattern matched against the Err error.
Parameters
ParameterType
errorV
Returns

object

NameTypeDefined in
errorVindex.ts:48
tag"Err"index.ts:48

ok()

Call Signature

ts
function ok(): object;

Defined in: index.ts:34

A ts-pattern pattern matching the Ok variant of a Result. With no argument it matches any Ok; pass a sub-pattern to constrain or select the value — a literal, or any ts-pattern pattern (e.g. ts-pattern's own P.string / P.select(), imported from ts-pattern, not this package).

Returns

object

NameTypeDefined in
tag"Ok"index.ts:34

Call Signature

ts
function ok<V>(value): object;

Defined in: index.ts:35

A ts-pattern pattern matching the Ok variant of a Result. With no argument it matches any Ok; pass a sub-pattern to constrain or select the value — a literal, or any ts-pattern pattern (e.g. ts-pattern's own P.string / P.select(), imported from ts-pattern, not this package).

Type Parameters
Type ParameterDescription
Vthe sub-pattern matched against the Ok value.
Parameters
ParameterType
valueV
Returns

object

NameTypeDefined in
tag"Ok"index.ts:35
valueVindex.ts:35

tag()

ts
function tag<Tag>(value): object;

Defined in: index.ts:80

A ts-pattern pattern matching any value whose _tag equals value (e.g. a TaggedError). Equivalent to the object pattern { _tag: value }, but reads better nested inside an err pattern and narrows to the matching variant — including its payload.

Type Parameters

Type ParameterDescription
Tag extends stringthe string literal tag to match.

Parameters

ParameterTypeDescription
valueTagthe _tag to match.

Returns

object

NameTypeDefined in
_tagTagindex.ts:80

Example

ts
.with(P.err(P.tag("Forbidden")), ({ error }) => error.user)

Released under the MIT License.