Module / v1.0.0-beta.13

@typed/guard

32 unique exports available through this public import path, including their members and aliases.

import * as guard from "@typed/guard";

Alternative selection

  • any

    function

    Runs candidates sequentially and returns the first match tagged with its key. Candidates are snapshotted from own enumerable keys when any is called. ECMAScript own-key order applies: integer-index strings, other strings, then symbols.

Effectful observation

  • tap

    variable

    Runs a synchronous or Effectful observation for each matched value and returns the value unchanged.

Error recovery

  • catch

    variable · Re-export

    Recovers typed failures and lifts the recovery result into Some.

  • catchAll

    variable

    Recovers typed failures and lifts the recovery result into Some.

  • catchCause

    variable

    Recovers from the complete Effect Cause and lifts the recovery result into Some.

  • catchTag

    variable

    Recovers selected tagged typed failures and leaves unmatched tags in the error channel.

Guard contracts

  • AsGuard

    interface

    An object that supplies a Guard through an own callable asGuard property. Use an instance field rather than a prototype method.

  • Guard

    type-alias

    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.

  • GuardInput

    type-alias

    A Guard or an object that supplies one. Guard combinators accept either form.

Input selection

  • filter

    variable

    Keeps matched values that satisfy a predicate or refinement.

  • filterMap

    variable

    Refines and maps a matched value with an Option-returning function.

  • liftPredicate

    function

    Builds a Guard from a predicate or refinement. The predicate is evaluated only when the returned Effect runs. A thrown exception becomes an Effect defect; use an effectful Guard when failure belongs in the typed error channel.

Library adapters

  • getGuard

    variable · Re-export

    Returns a callable Guard unchanged or obtains one from an own callable asGuard property. Invalid adapter objects throw TypeError immediately.

Record construction

  • addTag

    variable

    Adds a readonly _tag to every matched object output. The output must not already have an _tag property.

  • bind

    variable

    Runs f on a matched object and adds its matched value under a new key. The key must not already exist. Enumerable getters and proxy traps may execute during the object spread.

  • bindTo

    variable

    Wraps any matched output in a new object under key. This is the explicit transition from an arbitrary output to the record-building workflow.

  • let

    variable · Re-export

    Adds a fixed property to every matched record output.

Schema decoding and encoding

  • decode

    variable

    Decodes each matched encoded value through an Effect Schema.

  • encode

    variable

    Encodes each matched schema Type to its Encoded representation.

  • fromSchemaDecode

    function

    Creates a Guard that decodes a schema’s Encoded input to its Type.

  • fromSchemaEncode

    function

    Creates a Guard that encodes a schema’s Type to its Encoded representation.

Sequential composition

  • pipe

    variable

    Runs output only when input matches. None short-circuits successfully, while failures and service requirements are preserved from both Guards.

Services

  • provide

    variable

    Provides a Context or Layer to a Guard’s Effect.

  • provideService

    variable

    Provides one concrete service to a Guard.

  • provideServiceEffect

    variable

    Provides a service produced by an Effect to a Guard.

Type utilities

  • AnyInput

    type-alias

    Computes the intersection of inputs accepted by an any Guard record.

  • AnyOutput

    type-alias

    Builds the tagged output union produced by any.

  • Guard.Error

    type-alias

    Extracts the typed error channel from a Guard or Guard adapter.

  • Guard.Input

    type-alias

    Extracts the accepted input type from a Guard or Guard adapter.

  • Guard.Output

    type-alias

    Extracts the matched output type from a Guard or Guard adapter.

  • Guard.Services

    type-alias

    Extracts the Effect service requirements from a Guard or Guard adapter.

Value transformations

  • map

    variable

    Maps matched output synchronously while preserving non-match and Effect channels.

  • mapEffect

    variable

    Maps matched output with an Effect while preserving None.