decode

package
v2.1.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decode

type Decode[I, A any] = Reader[I, Validation[A]]

Decode is a function that decodes input I to type A with validation. It returns a Validation result directly.

func MonadAp

func MonadAp[B, I, A any](fab Decode[I, func(A) B], fa Decode[I, A]) Decode[I, B]

MonadAp applies a decoder containing a function to a decoder containing a value. This is the applicative apply operation that enables parallel composition of decoders.

Example:

decoderFn := decode.Of[string](func(n int) string {
    return fmt.Sprintf("Number: %d", n)
})
decoderVal := decode.Of[string](42)
result := decode.MonadAp(decoderFn, decoderVal)

func MonadChain

func MonadChain[I, A, B any](fa Decode[I, A], f Kleisli[I, A, B]) Decode[I, B]

MonadChain sequences two decode operations, passing the result of the first to the second. This is the monadic bind operation that enables sequential composition of decoders.

Example:

decoder1 := decode.Of[string](42)
decoder2 := decode.MonadChain(decoder1, func(n int) Decode[string, string] {
    return decode.Of[string](fmt.Sprintf("Number: %d", n))
})

func MonadMap

func MonadMap[I, A, B any](fa Decode[I, A], f func(A) B) Decode[I, B]

MonadMap transforms the decoded value using the provided function. This is the functor map operation that applies a transformation to successful decode results.

Example:

decoder := decode.Of[string](42)
mapped := decode.MonadMap(decoder, func(n int) string {
    return fmt.Sprintf("Number: %d", n)
})

func Of

func Of[I, A any](a A) Decode[I, A]

Of creates a Decode that always succeeds with the given value. This is the pointed functor operation that lifts a pure value into the Decode context.

Example:

decoder := decode.Of[string](42)
result := decoder("any input") // Always returns validation.Success(42)

type Kleisli

type Kleisli[I, A, B any] = Reader[A, Decode[I, B]]

Kleisli represents a function from A to a decoded B given input type I. It's a Reader that takes an input A and produces a Decode[I, B] function. This enables composition of decoding operations in a functional style.

type Operator

type Operator[I, A, B any] = Kleisli[I, Decode[I, A], B]

Operator represents a decoding transformation that takes a decoded A and produces a decoded B. It's a specialized Kleisli arrow for composing decode operations where the input is already decoded. This allows chaining multiple decode transformations together.

func Ap

func Ap[B, I, A any](fa Decode[I, A]) Operator[I, func(A) B, B]

Ap creates an operator that applies a function decoder to a value decoder. This is the curried version of MonadAp, useful for composition pipelines.

Example:

apOp := decode.Ap[string](decode.Of[string](42))
decoderFn := decode.Of[string](func(n int) string {
    return fmt.Sprintf("Number: %d", n)
})
result := apOp(decoderFn)

func Chain

func Chain[I, A, B any](f Kleisli[I, A, B]) Operator[I, A, B]

Chain creates an operator that sequences decode operations. This is the curried version of MonadChain, useful for composition pipelines.

Example:

chainOp := decode.Chain(func(n int) Decode[string, string] {
    return decode.Of[string](fmt.Sprintf("Number: %d", n))
})
decoder := chainOp(decode.Of[string](42))

func Map

func Map[I, A, B any](f func(A) B) Operator[I, A, B]

Map creates an operator that transforms decoded values. This is the curried version of MonadMap, useful for composition pipelines.

Example:

mapOp := decode.Map(func(n int) string {
    return fmt.Sprintf("Number: %d", n)
})
decoder := mapOp(decode.Of[string](42))

type Reader

type Reader[R, A any] = reader.Reader[R, A]

Reader represents a computation that depends on an environment R and produces a value A.

type Validation

type Validation[A any] = validation.Validation[A]

Validation represents the result of a validation operation that may contain validation errors or a successfully validated value of type A.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL