# GuardType

An effectful partial transformation.

A successful `Some` contains a match, a successful `None` means the input did
not match, and an Effect failure remains in the `E` channel. Required
services remain in `R`.

## Signatures

```ts
export type GuardType<in I, out O, out E = never, out R = never> = (input: I) => Effect.Effect<Option.Option<O>, E, R>;
```

```ts
export declare namespace GuardType {
    type Input<T> = [
        T
    ] extends [
        Guard<infer I, infer _R, infer _E, infer _O>
    ] ? I : [
        T
    ] extends [
        AsGuard<infer I, infer _R, infer _E, infer _O>
    ] ? I : never;
    type Services<T> = [
        T
    ] extends [
        Guard<infer _I, infer _O, infer _E, infer R>
    ] ? R : [
        T
    ] extends [
        AsGuard<infer _I, infer _O, infer _E, infer R>
    ] ? R : never;
    type Error<T> = [
        T
    ] extends [
        Guard<infer _I, infer _O, infer E, infer _R>
    ] ? E : [
        T
    ] extends [
        AsGuard<infer _I, infer _O, infer E, infer _R>
    ] ? E : never;
    type Output<T> = [
        T
    ] extends [
        Guard<infer _I, infer O, infer _E, infer _R>
    ] ? O : [
        T
    ] extends [
        AsGuard<infer _I, infer O, infer _E, infer _R>
    ] ? O : never;
}
```

## Why

`Guard` models non-match as successful `None`, keeping ordinary dispatch separate from typed failure, defects, and interruption in Effect's Cause.

## Ownership and lifetime

A Guard acquires no resources by itself; each invocation has the lifetime and service requirements of the returned Effect.

See [Effect Option](https://effect.website/docs/data-types/option/) and [Effect error management](https://effect.website/docs/v4/error-management/expected-errors/).

## Examples

```ts
import type { Guard } from "@typed/guard"
import { Effect, Option } from "effect"
const string: Guard<unknown, string> = (input) => Effect.succeed(typeof input === "string" ? Option.some(input) : Option.none())
```
