@unthrown/pattern
@unthrown/pattern
Functions
defect()
Call Signature
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
| Name | Type | Defined in |
|---|---|---|
tag | "Defect" | index.ts:60 |
Call Signature
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 Parameter | Description |
|---|---|
V | the sub-pattern matched against the Defect cause. |
Parameters
| Parameter | Type |
|---|---|
cause | V |
Returns
object
| Name | Type | Defined in |
|---|---|---|
cause | V | index.ts:61 |
tag | "Defect" | index.ts:61 |
err()
Call Signature
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
| Name | Type | Defined in |
|---|---|---|
tag | "Err" | index.ts:47 |
Call Signature
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 Parameter | Description |
|---|---|
V | the sub-pattern matched against the Err error. |
Parameters
| Parameter | Type |
|---|---|
error | V |
Returns
object
| Name | Type | Defined in |
|---|---|---|
error | V | index.ts:48 |
tag | "Err" | index.ts:48 |
ok()
Call Signature
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
| Name | Type | Defined in |
|---|---|---|
tag | "Ok" | index.ts:34 |
Call Signature
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 Parameter | Description |
|---|---|
V | the sub-pattern matched against the Ok value. |
Parameters
| Parameter | Type |
|---|---|
value | V |
Returns
object
| Name | Type | Defined in |
|---|---|---|
tag | "Ok" | index.ts:35 |
value | V | index.ts:35 |
tag()
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 Parameter | Description |
|---|---|
Tag extends string | the string literal tag to match. |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | Tag | the _tag to match. |
Returns
object
| Name | Type | Defined in |
|---|---|---|
_tag | Tag | index.ts:80 |
Example
.with(P.err(P.tag("Forbidden")), ({ error }) => error.user)