ioresult

package
v2.2.52 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package ioresult provides functional programming combinators for working with IO operations that can fail with errors, following Go's idiomatic (value, error) tuple pattern.

Overview

IOResult[A] represents a computation that performs IO and returns either a value of type A or an error. It is defined as:

type IOResult[A any] = func() (A, error)

This is the idiomatic Go version of IOEither, using Go's standard error handling pattern instead of the Either monad. It combines:

  • IO effects (functions that perform side effects)
  • Error handling via Go's (value, error) tuple return pattern

Why Parameterless Functions Represent IO Operations

The key insight behind IOResult is that a function returning a value without taking any input can only produce that value through side effects. Consider:

func() int { return 42 }              // Pure: always returns 42
func() int { return readFromFile() }  // Impure: result depends on external state

When a parameterless function returns different values on different calls, or when it interacts with the outside world (filesystem, network, random number generator, current time, database), it is performing a side effect - an observable interaction with state outside the function's scope.

Lazy Evaluation and Referential Transparency

IOResult provides two critical benefits:

  1. **Lazy Evaluation**: The side effect doesn't happen when you create the IOResult, only when you call it (execute it). This allows you to build complex computations as pure data structures and defer execution until needed.

    // This doesn't read the file yet, just describes how to read it readConfig := func() (Config, error) { return os.ReadFile("config.json") }

    // Still hasn't read the file, just composed operations parsed := Map(parseJSON)(readConfig)

    // NOW it reads the file and parses it config, err := parsed()

  2. **Referential Transparency of the Description**: While the IO operation itself has side effects, the IOResult value (the function) is referentially transparent. You can pass it around, compose it, and reason about it without triggering the side effect. The side effect only occurs when you explicitly call the function.

Distinguishing Pure from Impure Operations

The type system makes the distinction clear:

// Pure function: always returns the same output for the same input
func double(x int) int { return x * 2 }

// Impure operation: encapsulated in IOResult
func readFile(path string) IOResult[[]byte] {
    return func() ([]byte, error) {
        return os.ReadFile(path)  // Side effect: file system access
    }
}

The IOResult type explicitly marks operations as having side effects, making the distinction between pure and impure code visible in the type system. This allows developers to:

  • Identify which parts of the code interact with external state
  • Test pure logic separately from IO operations
  • Compose IO operations while keeping them lazy
  • Control when and where side effects occur

Examples of Side Effects Captured by IOResult

IOResult is appropriate for operations that:

  • Read from or write to files, databases, or network
  • Generate random numbers
  • Read the current time
  • Modify mutable state
  • Interact with external APIs
  • Execute system commands
  • Acquire or release resources

Example:

// Each call potentially returns a different value
getCurrentTime := func() (time.Time, error) {
    return time.Now(), nil  // Side effect: reads system clock
}

// Each call reads from external state
readDatabase := func() (User, error) {
    return db.Query("SELECT * FROM users WHERE id = ?", 1)
}

// Composes multiple IO operations
pipeline := F.Pipe2(
    getCurrentTime,
    Chain(func(t time.Time) IOResult[string] {
        return func() (string, error) {
            return fmt.Sprintf("Time: %v", t), nil
        }
    }),
)

Core Concepts

IOResult follows functional programming principles:

  • Functor: Transform successful values with Map
  • Applicative: Combine multiple IOResults with Ap, ApS
  • Monad: Chain dependent computations with Chain, Bind
  • Error recovery: Handle errors with ChainLeft, Alt

Basic Usage

Creating IOResult values:

success := Of(42)                          // Right value
failure := Left[int](errors.New("error"))  // Left (error) value

Transforming values:

doubled := Map(N.Mul(2))(success)

Chaining computations:

result := Chain(func(x int) IOResult[string] {
    return Of(fmt.Sprintf("%d", x))
})(success)

Do Notation

The package supports do-notation style composition for building complex computations:

result := F.Pipe5(
    Of("John"),
    BindTo(T.Of[string]),
    ApS(T.Push1[string, int], Of(42)),
    Bind(T.Push2[string, int, string], func(t T.Tuple2[string, int]) IOResult[string] {
        return Of(fmt.Sprintf("%s: %d", t.F1, t.F2))
    }),
    Map(transform),
)

Error Handling

IOResult provides several ways to handle errors:

  • ChainLeft: Transform error values into new computations
  • Alt: Provide alternative computations when an error occurs
  • GetOrElse: Extract values with a default for errors
  • Fold: Handle both success and error cases explicitly

Concurrency

IOResult supports both sequential and parallel execution:

  • ApSeq, TraverseArraySeq: Sequential execution
  • ApPar, TraverseArrayPar: Parallel execution (default)
  • Ap, TraverseArray: Defaults to parallel execution

Resource Management

The package provides resource management utilities:

  • Bracket: Acquire, use, and release resources safely
  • WithResource: Scoped resource management
  • WithLock: Execute operations within a lock scope

Conversion Functions

IOResult interoperates with other types:

  • FromEither: Convert Either to IOResult
  • FromResult: Convert (value, error) tuple to IOResult
  • FromOption: Convert Option to IOResult
  • FromIO: Convert pure IO to IOResult (always succeeds)

Examples

See the example tests for detailed usage patterns:

  • examples_create_test.go: Creating IOResult values
  • examples_do_test.go: Using do-notation
  • examples_extract_test.go: Extracting values from IOResult

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApSeq

func ApSeq[B, A any](ma IOResult[A]) func(IOResult[func(A) B]) IOResult[B]

ApSeq returns an operator that applies a function to a value sequentially. This is the operator form of MonadApSeq.

func ChainOptionK

func ChainOptionK[A, B any](onNone Lazy[error]) func(func(A) (B, bool)) Operator[A, B]

ChainOptionK chains a function that returns an Option (value, bool). The None case (false) is converted to an error using onNone.

func Eitherize0

func Eitherize0[F ~func() (R, error), R any](f F) func() IOResult[R]

func Eitherize1

func Eitherize1[F ~func(T1) (R, error), T1, R any](f F) func(T1) IOResult[R]

func Eitherize2

func Eitherize2[F ~func(T1, T2) (R, error), T1, T2, R any](f F) func(T1, T2) IOResult[R]

func Eitherize3

func Eitherize3[F ~func(T1, T2, T3) (R, error), T1, T2, T3, R any](f F) func(T1, T2, T3) IOResult[R]

func Eq

func Eq[A any](eq func(A, error) func(A, error) bool) EQ.Eq[IOResult[A]]

Eq implements the equals predicate for values contained in the IOEither monad Eq constructs an equality predicate for IOResult values. The comparison function receives (value, error) tuples from both IOResults.

func Fold

func Fold[A, B any](onLeft func(error) IO[B], onRight io.Kleisli[A, B]) func(IOResult[A]) IO[B]

Fold returns a function that handles both error and success cases, converting to IO. This is the operator form of MonadFold for pattern matching on IOResult.

func FromOption

func FromOption[A any](onNone Lazy[error]) func(A, bool) IOResult[A]

FromOption converts an Option (represented as value, bool) to an IOResult. If the bool is true, the value is wrapped in a successful IOResult. If the bool is false, onNone is called to generate the error.

func FromStrictEquals

func FromStrictEquals[A comparable]() EQ.Eq[IOResult[A]]

FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function FromStrictEquals constructs an Eq from Go's built-in equality (==) for comparable types. Both the value and error must match for two IOResults to be considered equal.

func Functor

func Functor[A, B any]() functor.Functor[A, B, IOResult[A], IOResult[B]]

Functor implements the monadic operations for [IOEither] Functor returns a Functor instance for IOResult. Functor provides the Map operation for transforming values.

func GetOrElse

func GetOrElse[A any](onLeft func(error) IO[A]) func(IOResult[A]) IO[A]

GetOrElse extracts the value from an IOResult, using a default IO for error cases. This converts an IOResult to an IO that cannot fail.

func Monad

func Monad[A, B any]() monad.Monad[A, B, IOResult[A], IOResult[B], IOResult[func(A) B]]

Monad implements the monadic operations for [IOEither] Monad returns a Monad instance for IOResult. Monad provides the full monadic interface including Map, Chain, and Ap.

func MonadPar

func MonadPar[A, B any]() monad.Monad[A, B, IOResult[A], IOResult[B], IOResult[func(A) B]]

Monad implements the monadic operations for [IOEither] Monad returns a Monad instance for IOResult. Monad provides the full monadic interface including Map, Chain, and Ap.

func MonadSeq

func MonadSeq[A, B any]() monad.Monad[A, B, IOResult[A], IOResult[B], IOResult[func(A) B]]

Monad implements the monadic operations for [IOEither] Monad returns a Monad instance for IOResult. Monad provides the full monadic interface including Map, Chain, and Ap.

func Pointed

func Pointed[A any]() pointed.Pointed[A, IOResult[A]]

Pointed implements the pointed operations for [IOEither] Pointed returns a Pointed instance for IOResult. Pointed provides the ability to lift pure values into the IOResult context.

func TraverseParTuple1

func TraverseParTuple1[E error, F1 ~func(A1) IOResult[T1], T1, A1 any](f1 F1) func(tuple.Tuple1[A1]) IOResult[tuple.Tuple1[T1]]

TraverseParTuple1 converts a [tuple.Tuple1[A1]] into a [IOResult[tuple.Tuple1[T1]]]

func TraverseParTuple2

func TraverseParTuple2[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], T1, T2, A1, A2 any](f1 F1, f2 F2) func(tuple.Tuple2[A1, A2]) IOResult[tuple.Tuple2[T1, T2]]

TraverseParTuple2 converts a [tuple.Tuple2[A1, A2]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func TraverseParTuple3

func TraverseParTuple3[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], T1, T2, T3, A1, A2, A3 any](f1 F1, f2 F2, f3 F3) func(tuple.Tuple3[A1, A2, A3]) IOResult[tuple.Tuple3[T1, T2, T3]]

TraverseParTuple3 converts a [tuple.Tuple3[A1, A2, A3]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func TraverseParTuple4

func TraverseParTuple4[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], T1, T2, T3, T4, A1, A2, A3, A4 any](f1 F1, f2 F2, f3 F3, f4 F4) func(tuple.Tuple4[A1, A2, A3, A4]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

TraverseParTuple4 converts a [tuple.Tuple4[A1, A2, A3, A4]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func TraverseParTuple5

func TraverseParTuple5[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], T1, T2, T3, T4, T5, A1, A2, A3, A4, A5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func(tuple.Tuple5[A1, A2, A3, A4, A5]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

TraverseParTuple5 converts a [tuple.Tuple5[A1, A2, A3, A4, A5]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func TraverseParTuple6

func TraverseParTuple6[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], T1, T2, T3, T4, T5, T6, A1, A2, A3, A4, A5, A6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func(tuple.Tuple6[A1, A2, A3, A4, A5, A6]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

TraverseParTuple6 converts a [tuple.Tuple6[A1, A2, A3, A4, A5, A6]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func TraverseParTuple7

func TraverseParTuple7[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], T1, T2, T3, T4, T5, T6, T7, A1, A2, A3, A4, A5, A6, A7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func(tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

TraverseParTuple7 converts a [tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func TraverseParTuple8

func TraverseParTuple8[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], T1, T2, T3, T4, T5, T6, T7, T8, A1, A2, A3, A4, A5, A6, A7, A8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func(tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

TraverseParTuple8 converts a [tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseParTuple9

func TraverseParTuple9[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], T1, T2, T3, T4, T5, T6, T7, T8, T9, A1, A2, A3, A4, A5, A6, A7, A8, A9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func(tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

TraverseParTuple9 converts a [tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func TraverseParTuple10

func TraverseParTuple10[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], F10 ~func(A10) IOResult[T10], T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func(tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

TraverseParTuple10 converts a [tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func TraverseSeqTuple1

func TraverseSeqTuple1[E error, F1 ~func(A1) IOResult[T1], T1, A1 any](f1 F1) func(tuple.Tuple1[A1]) IOResult[tuple.Tuple1[T1]]

TraverseSeqTuple1 converts a [tuple.Tuple1[A1]] into a [IOResult[tuple.Tuple1[T1]]]

func TraverseSeqTuple2

func TraverseSeqTuple2[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], T1, T2, A1, A2 any](f1 F1, f2 F2) func(tuple.Tuple2[A1, A2]) IOResult[tuple.Tuple2[T1, T2]]

TraverseSeqTuple2 converts a [tuple.Tuple2[A1, A2]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func TraverseSeqTuple3

func TraverseSeqTuple3[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], T1, T2, T3, A1, A2, A3 any](f1 F1, f2 F2, f3 F3) func(tuple.Tuple3[A1, A2, A3]) IOResult[tuple.Tuple3[T1, T2, T3]]

TraverseSeqTuple3 converts a [tuple.Tuple3[A1, A2, A3]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func TraverseSeqTuple4

func TraverseSeqTuple4[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], T1, T2, T3, T4, A1, A2, A3, A4 any](f1 F1, f2 F2, f3 F3, f4 F4) func(tuple.Tuple4[A1, A2, A3, A4]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

TraverseSeqTuple4 converts a [tuple.Tuple4[A1, A2, A3, A4]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func TraverseSeqTuple5

func TraverseSeqTuple5[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], T1, T2, T3, T4, T5, A1, A2, A3, A4, A5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func(tuple.Tuple5[A1, A2, A3, A4, A5]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

TraverseSeqTuple5 converts a [tuple.Tuple5[A1, A2, A3, A4, A5]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func TraverseSeqTuple6

func TraverseSeqTuple6[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], T1, T2, T3, T4, T5, T6, A1, A2, A3, A4, A5, A6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func(tuple.Tuple6[A1, A2, A3, A4, A5, A6]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

TraverseSeqTuple6 converts a [tuple.Tuple6[A1, A2, A3, A4, A5, A6]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func TraverseSeqTuple7

func TraverseSeqTuple7[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], T1, T2, T3, T4, T5, T6, T7, A1, A2, A3, A4, A5, A6, A7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func(tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

TraverseSeqTuple7 converts a [tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func TraverseSeqTuple8

func TraverseSeqTuple8[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], T1, T2, T3, T4, T5, T6, T7, T8, A1, A2, A3, A4, A5, A6, A7, A8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func(tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

TraverseSeqTuple8 converts a [tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseSeqTuple9

func TraverseSeqTuple9[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], T1, T2, T3, T4, T5, T6, T7, T8, T9, A1, A2, A3, A4, A5, A6, A7, A8, A9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func(tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

TraverseSeqTuple9 converts a [tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func TraverseSeqTuple10

func TraverseSeqTuple10[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], F10 ~func(A10) IOResult[T10], T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func(tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

TraverseSeqTuple10 converts a [tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func TraverseTuple1

func TraverseTuple1[E error, F1 ~func(A1) IOResult[T1], T1, A1 any](f1 F1) func(tuple.Tuple1[A1]) IOResult[tuple.Tuple1[T1]]

TraverseTuple1 converts a [tuple.Tuple1[A1]] into a [IOResult[tuple.Tuple1[T1]]]

func TraverseTuple2

func TraverseTuple2[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], T1, T2, A1, A2 any](f1 F1, f2 F2) func(tuple.Tuple2[A1, A2]) IOResult[tuple.Tuple2[T1, T2]]

TraverseTuple2 converts a [tuple.Tuple2[A1, A2]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func TraverseTuple3

func TraverseTuple3[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], T1, T2, T3, A1, A2, A3 any](f1 F1, f2 F2, f3 F3) func(tuple.Tuple3[A1, A2, A3]) IOResult[tuple.Tuple3[T1, T2, T3]]

TraverseTuple3 converts a [tuple.Tuple3[A1, A2, A3]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func TraverseTuple4

func TraverseTuple4[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], T1, T2, T3, T4, A1, A2, A3, A4 any](f1 F1, f2 F2, f3 F3, f4 F4) func(tuple.Tuple4[A1, A2, A3, A4]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

TraverseTuple4 converts a [tuple.Tuple4[A1, A2, A3, A4]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func TraverseTuple5

func TraverseTuple5[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], T1, T2, T3, T4, T5, A1, A2, A3, A4, A5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func(tuple.Tuple5[A1, A2, A3, A4, A5]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

TraverseTuple5 converts a [tuple.Tuple5[A1, A2, A3, A4, A5]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func TraverseTuple6

func TraverseTuple6[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], T1, T2, T3, T4, T5, T6, A1, A2, A3, A4, A5, A6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func(tuple.Tuple6[A1, A2, A3, A4, A5, A6]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

TraverseTuple6 converts a [tuple.Tuple6[A1, A2, A3, A4, A5, A6]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func TraverseTuple7

func TraverseTuple7[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], T1, T2, T3, T4, T5, T6, T7, A1, A2, A3, A4, A5, A6, A7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func(tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

TraverseTuple7 converts a [tuple.Tuple7[A1, A2, A3, A4, A5, A6, A7]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func TraverseTuple8

func TraverseTuple8[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], T1, T2, T3, T4, T5, T6, T7, T8, A1, A2, A3, A4, A5, A6, A7, A8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func(tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

TraverseTuple8 converts a [tuple.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseTuple9

func TraverseTuple9[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], T1, T2, T3, T4, T5, T6, T7, T8, T9, A1, A2, A3, A4, A5, A6, A7, A8, A9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func(tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

TraverseTuple9 converts a [tuple.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func TraverseTuple10

func TraverseTuple10[E error, F1 ~func(A1) IOResult[T1], F2 ~func(A2) IOResult[T2], F3 ~func(A3) IOResult[T3], F4 ~func(A4) IOResult[T4], F5 ~func(A5) IOResult[T5], F6 ~func(A6) IOResult[T6], F7 ~func(A7) IOResult[T7], F8 ~func(A8) IOResult[T8], F9 ~func(A9) IOResult[T9], F10 ~func(A10) IOResult[T10], T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func(tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

TraverseTuple10 converts a [tuple.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

Types

type Endomorphism

type Endomorphism[A any] = endomorphism.Endomorphism[A]

Endomorphism represents a function from type A to type A.

type IO

type IO[A any] = io.IO[A]

IO represents a computation that performs side effects and returns a value of type A.

func MonadFold

func MonadFold[A, B any](ma IOResult[A], onLeft func(error) IO[B], onRight io.Kleisli[A, B]) IO[B]

MonadFold handles both error and success cases explicitly, converting to an IO. This is useful for pattern matching on the IOResult.

type IOResult

type IOResult[A any] = func() (A, error)

IOResult represents a computation that performs IO and may fail with an error. It follows Go's idiomatic pattern of returning (value, error) tuples. A successful computation returns (value, nil), while a failed one returns (zero, error).

Example (Creation)
// Build an IOResult
leftValue := Left[string](fmt.Errorf("some error"))
rightValue := Right("value")

// Convert from Either
eitherValue := E.Of[error](42)
ioFromEither := FromEither(eitherValue)

// some predicate
isEven := func(num int) (int, error) {
	if num%2 == 0 {
		return num, nil
	}
	return 0, fmt.Errorf("%d is an odd number", num)
}
fromEven := Eitherize1(isEven)
leftFromPred := fromEven(3)
rightFromPred := fromEven(4)

// Convert results to Either for display
val1, err1 := leftValue()
if err1 != nil {
	fmt.Printf("Left[*errors.errorString](%s)\n", err1.Error())
} else {
	fmt.Printf("Right[string](%s)\n", val1)
}

val2, err2 := rightValue()
if err2 != nil {
	fmt.Printf("Left[*errors.errorString](%s)\n", err2.Error())
} else {
	fmt.Printf("Right[string](%s)\n", val2)
}

val3, err3 := ioFromEither()
if err3 != nil {
	fmt.Printf("Left[*errors.errorString](%s)\n", err3.Error())
} else {
	fmt.Printf("Right[int](%d)\n", val3)
}

val4, err4 := leftFromPred()
if err4 != nil {
	fmt.Printf("Left[*errors.errorString](%s)\n", err4.Error())
} else {
	fmt.Printf("Right[int](%d)\n", val4)
}

val5, err5 := rightFromPred()
if err5 != nil {
	fmt.Printf("Left[*errors.errorString](%s)\n", err5.Error())
} else {
	fmt.Printf("Right[int](%d)\n", val5)
}
Output:
Left[*errors.errorString](some error)
Right[string](value)
Right[int](42)
Left[*errors.errorString](3 is an odd number)
Right[int](4)
Example (Do)
foo := Of("foo")
bar := Of(1)

// quux consumes the state of three bindings and returns an [IO] instead of an [IOResult]
quux := func(t T.Tuple3[string, int, string]) IO[Void] {
	return io.FromImpure(func() {
		log.Printf("t1: %s, t2: %d, t3: %s", t.F1, t.F2, t.F3)
	})
}

transform := func(t T.Tuple3[string, int, string]) int {
	return len(t.F1) + t.F2 + len(t.F3)
}

b := F.Pipe5(
	foo,
	BindTo(T.Of[string]),
	ApS(T.Push1[string, int], bar),
	Bind(T.Push2[string, int, string], func(t T.Tuple2[string, int]) IOResult[string] {
		return Of(fmt.Sprintf("%s%d", t.F1, t.F2))
	}),
	ChainFirstIOK(quux),
	Map(transform),
)

val, err := b()
if err != nil {
	fmt.Printf("Left[error](%s)\n", err.Error())
} else {
	fmt.Printf("Right[int](%d)\n", val)
}
Output:
Right[int](8)
Example (Extraction)
// IOResult
someIOResult := Right(42)
value, err := someIOResult() // (42, nil)
if err == nil {
	fmt.Println(E.Of[error](value)) // Convert to Either for display
}

// Or more directly using GetOrElse
infallibleIO := GetOrElse(F.Constant1[error](io.Of(0)))(someIOResult) // => io returns 42
valueFromIO := infallibleIO()                                         // => 42

fmt.Println(value)
fmt.Println(valueFromIO)
Output:
Right[int](42)
42
42

func Bracket

func Bracket[A, B, ANY any](
	acquire IOResult[A],
	use Kleisli[A, B],
	release func(B, error) func(A) IOResult[ANY],
) IOResult[B]

Bracket makes sure that a resource is cleaned up in the event of an error. The release action is called regardless of whether the body action returns and error or not.

func Defer

func Defer[A any](gen Lazy[IOResult[A]]) IOResult[A]

Defer defers the creation of an IOResult until it is executed. This allows lazy evaluation of the IOResult itself.

func Do

func Do[S any](
	empty S,
) IOResult[S]

Do starts a do-notation computation with an initial state. This is the entry point for building complex computations using the do-notation style.

func Flatten

func Flatten[A any](mma IOResult[IOResult[A]]) IOResult[A]

Flatten removes one level of nesting from a nested IOResult. This is equivalent to joining or flattening the structure: IOResult[IOResult[A]] -> IOResult[A].

func FromEither

func FromEither[A any](e Result[A]) IOResult[A]

FromEither converts an Either (Result[A]) to an IOResult. Either's Left becomes an error, Either's Right becomes a successful value.

func FromIO

func FromIO[A any](mr IO[A]) IOResult[A]

FromIO converts an IO computation to an IOResult that always succeeds. This is an alias for RightIO.

func FromImpure

func FromImpure(f func()) IOResult[Void]

FromImpure converts an impure side-effecting function into an IOResult. The function is executed when the IOResult runs, and always succeeds with nil.

func FromLazy

func FromLazy[A any](mr Lazy[A]) IOResult[A]

FromLazy converts a lazy computation to an IOResult that always succeeds. This is an alias for FromIO since Lazy and IO are equivalent.

func FromResult

func FromResult[A any](a A, err error) IOResult[A]

FromResult converts a (value, error) tuple to an IOResult. This is the primary way to convert Go's standard error handling pattern to IOResult.

func Left

func Left[A any](l error) IOResult[A]

Left creates an IOResult that represents a failed computation with the given error. When executed, it returns the zero value for type A and the provided error.

func LeftIO

func LeftIO[A any](ml IO[error]) IOResult[A]

LeftIO creates an IOResult from an IO computation that produces an error. The error from the IO is used as the Left value.

func Memoize

func Memoize[A any](ma IOResult[A]) IOResult[A]

Memoize caches the result of an IOResult so it only executes once. Subsequent calls return the cached result without re-executing the computation.

func MonadAlt

func MonadAlt[A any](first IOResult[A], second Lazy[IOResult[A]]) IOResult[A]

MonadAlt tries the first IOResult, and if it fails, tries the second. This provides a fallback mechanism for error recovery.

func MonadAp

func MonadAp[B, A any](mab IOResult[func(A) B], ma IOResult[A]) IOResult[B]

MonadAp applies a function wrapped in IOResult to a value wrapped in IOResult. This is the Applicative apply operation. The implementation delegates to either the parallel (MonadApPar) or sequential (MonadApSeq) version based on useParallel flag.

func MonadApFirst

func MonadApFirst[A, B any](first IOResult[A], second IOResult[B]) IOResult[A]

MonadApFirst combines two effectful actions, keeping only the result of the first.

func MonadApPar

func MonadApPar[B, A any](mab IOResult[func(A) B], ma IOResult[A]) IOResult[B]

MonadApPar applies a function to a value, executing both in parallel. Both IOResults are executed concurrently for better performance.

func MonadApSecond

func MonadApSecond[A, B any](first IOResult[A], second IOResult[B]) IOResult[B]

MonadApSecond combines two effectful actions, keeping only the result of the second.

func MonadApSeq

func MonadApSeq[B, A any](mab IOResult[func(A) B], ma IOResult[A]) IOResult[B]

MonadApSeq applies a function to a value sequentially. The function IOResult is executed first, then the value IOResult.

func MonadBiMap

func MonadBiMap[A, B any](fa IOResult[A], f Endomorphism[error], g func(A) B) IOResult[B]

MonadBiMap transforms both the error (left) and success (right) values.

func MonadChain

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

MonadChain chains a kleisli function that depends on the current value. This is the Monad bind operation for IOResult.

func MonadChainEitherK

func MonadChainEitherK[A, B any](ma IOResult[A], f either.Kleisli[error, A, B]) IOResult[B]

MonadChainEitherK chains a function that returns an Either. The Either is converted to IOResult: Left becomes error, Right becomes success.

func MonadChainFirst

func MonadChainFirst[A, B any](ma IOResult[A], f Kleisli[A, B]) IOResult[A]

MonadChainFirst chains a computation but returns the original value if both succeed. If either computation fails, the error is returned.

func MonadChainFirstEitherK

func MonadChainFirstEitherK[A, B any](ma IOResult[A], f either.Kleisli[error, A, B]) IOResult[A]

MonadChainFirstEitherK runs an Either computation for side effects but returns the original value. The Either computation must succeed for the original value to be returned.

func MonadChainFirstIOK

func MonadChainFirstIOK[A, B any](ma IOResult[A], f io.Kleisli[A, B]) IOResult[A]

MonadChainFirstIOK runs an IO computation for side effects but returns the original value. The IO computation always succeeds, so errors from the original IOResult are preserved.

func MonadChainFirstLeft

func MonadChainFirstLeft[A, B any](ma IOResult[A], f Kleisli[error, B]) IOResult[A]

MonadChainFirstLeft runs a computation on the error but always returns the original error. This is useful for side effects like logging errors without recovery.

func MonadChainFirstResultK

func MonadChainFirstResultK[A, B any](ma IOResult[A], f result.Kleisli[A, B]) IOResult[A]

MonadChainFirstResultK runs a Result computation for side effects but returns the original value. The Result computation must succeed for the original value to be returned.

func MonadChainIOK

func MonadChainIOK[A, B any](ma IOResult[A], f io.Kleisli[A, B]) IOResult[B]

MonadChainIOK chains an IO kleisli function to an IOResult. If the IOResult fails, the function is not executed. Otherwise, the IO is executed and wrapped.

func MonadChainLeft

func MonadChainLeft[A any](fa IOResult[A], f Kleisli[error, A]) IOResult[A]

MonadChainLeft handles the error case by chaining to a new computation. If the IOResult succeeds, it passes through unchanged.

func MonadChainResultK

func MonadChainResultK[A, B any](ma IOResult[A], f result.Kleisli[A, B]) IOResult[B]

MonadChainResultK chains a function that returns a (value, error) tuple. This allows chaining standard Go functions that return errors.

func MonadChainTo

func MonadChainTo[A, B any](fa IOResult[A], fb IOResult[B]) IOResult[B]

MonadChainTo chains two IOResults, discarding the first value if successful. This is useful for sequencing computations where only the second result matters.

func MonadFlap

func MonadFlap[B, A any](fab IOResult[func(A) B], a A) IOResult[B]

MonadFlap applies a fixed argument to a function inside an IOResult. This is the reverse of Ap: the function is wrapped and the argument is fixed.

func MonadMap

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

MonadMap transforms the value inside an IOResult using the given function. If the IOResult is a Left (error), the function is not applied.

func MonadMapLeft

func MonadMapLeft[A any](fa IOResult[A], f Endomorphism[error]) IOResult[A]

MonadMapLeft transforms the error value using the given function. The success value is left unchanged.

func MonadMapTo

func MonadMapTo[A, B any](fa IOResult[A], b B) IOResult[B]

MonadMapTo replaces the value in an IOResult with a constant value. If the IOResult is an error, the error is preserved.

func MonadOf

func MonadOf[A any](r A) IOResult[A]

MonadOf is a monadic constructor that wraps a value in an IOResult. This is an alias for Of and provides the standard monad interface.

func MonadTap

func MonadTap[A, B any](ma IOResult[A], f Kleisli[A, B]) IOResult[A]

MonadTap executes a side effect but returns the original value. This is an alias for MonadChainFirst, useful for logging or side effects.

func MonadTapEitherK

func MonadTapEitherK[A, B any](ma IOResult[A], f either.Kleisli[error, A, B]) IOResult[A]

MonadTapEitherK executes an Either computation for side effects. This is an alias for MonadChainFirstEitherK.

func MonadTapIOK

func MonadTapIOK[A, B any](ma IOResult[A], f io.Kleisli[A, B]) IOResult[A]

MonadTapIOK executes an IO computation for side effects. This is an alias for MonadChainFirstIOK.

func MonadTapLeft

func MonadTapLeft[A, B any](ma IOResult[A], f Kleisli[error, B]) IOResult[A]

MonadTapLeft executes a side effect on errors without changing the error. This is an alias for MonadChainFirstLeft, useful for error logging.

func MonadTapResultK

func MonadTapResultK[A, B any](ma IOResult[A], f result.Kleisli[A, B]) IOResult[A]

MonadTapResultK executes a Result computation for side effects. This is an alias for MonadChainFirstResultK.

func Of

func Of[A any](r A) IOResult[A]

Of creates an IOResult that represents a successful computation with the given value. This is an alias for Right and is the Pointed functor implementation.

func Retrying

func Retrying[A any](
	policy R.RetryPolicy,
	action Kleisli[R.RetryStatus, A],
	check func(A, error) bool,
) IOResult[A]

Retrying retries an IOResult computation according to a retry policy. The action receives retry status information on each attempt. The check function determines if the result warrants another retry.

func Right[A any](r A) IOResult[A]

Right creates an IOResult that represents a successful computation with the given value. When executed, it returns the provided value and nil error.

func RightIO

func RightIO[A any](mr IO[A]) IOResult[A]

RightIO creates an IOResult from an IO computation that produces a value. The IO is executed and its result is wrapped in a successful IOResult.

func SequenceArray

func SequenceArray[A any](ma []IOResult[A]) IOResult[[]A]

SequenceArray converts a homogeneous sequence of either into an either of sequence SequenceArray converts an array of IOResults into an IOResult of an array. Uses parallel execution by default.

func SequenceArrayPar

func SequenceArrayPar[A any](ma []IOResult[A]) IOResult[[]A]

SequenceArrayPar converts a homogeneous Paruence of either into an either of Paruence SequenceArrayPar converts an array of IOResults in parallel (explicit).

func SequenceArraySeq

func SequenceArraySeq[A any](ma []IOResult[A]) IOResult[[]A]

SequenceArraySeq converts a homogeneous sequence of either into an either of sequence SequenceArraySeq converts an array of IOResults sequentially.

func SequenceParT1

func SequenceParT1[T1 any](
	t1 IOResult[T1],
) IOResult[tuple.Tuple1[T1]]

SequenceParT1 converts 1 [IOResult[T]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceParT2

func SequenceParT2[T1, T2 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
) IOResult[tuple.Tuple2[T1, T2]]

SequenceParT2 converts 2 [IOResult[T]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceParT3

func SequenceParT3[T1, T2, T3 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceParT3 converts 3 [IOResult[T]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceParT4

func SequenceParT4[T1, T2, T3, T4 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceParT4 converts 4 [IOResult[T]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceParT5

func SequenceParT5[T1, T2, T3, T4, T5 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceParT5 converts 5 [IOResult[T]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceParT6

func SequenceParT6[T1, T2, T3, T4, T5, T6 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceParT6 converts 6 [IOResult[T]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceParT7

func SequenceParT7[T1, T2, T3, T4, T5, T6, T7 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceParT7 converts 7 [IOResult[T]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceParT8

func SequenceParT8[T1, T2, T3, T4, T5, T6, T7, T8 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceParT8 converts 8 [IOResult[T]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceParT9

func SequenceParT9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceParT9 converts 9 [IOResult[T]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceParT10

func SequenceParT10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
	t10 IOResult[T10],
) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceParT10 converts 10 [IOResult[T]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func SequenceParTuple1

func SequenceParTuple1[T1 any](t tuple.Tuple1[IOResult[T1]]) IOResult[tuple.Tuple1[T1]]

SequenceParTuple1 converts a [tuple.Tuple1[IOResult[T]]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceParTuple2

func SequenceParTuple2[T1, T2 any](t tuple.Tuple2[IOResult[T1], IOResult[T2]]) IOResult[tuple.Tuple2[T1, T2]]

SequenceParTuple2 converts a [tuple.Tuple2[IOResult[T]]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceParTuple3

func SequenceParTuple3[T1, T2, T3 any](t tuple.Tuple3[IOResult[T1], IOResult[T2], IOResult[T3]]) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceParTuple3 converts a [tuple.Tuple3[IOResult[T]]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceParTuple4

func SequenceParTuple4[T1, T2, T3, T4 any](t tuple.Tuple4[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4]]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceParTuple4 converts a [tuple.Tuple4[IOResult[T]]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceParTuple5

func SequenceParTuple5[T1, T2, T3, T4, T5 any](t tuple.Tuple5[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5]]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceParTuple5 converts a [tuple.Tuple5[IOResult[T]]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceParTuple6

func SequenceParTuple6[T1, T2, T3, T4, T5, T6 any](t tuple.Tuple6[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6]]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceParTuple6 converts a [tuple.Tuple6[IOResult[T]]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceParTuple7

func SequenceParTuple7[T1, T2, T3, T4, T5, T6, T7 any](t tuple.Tuple7[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7]]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceParTuple7 converts a [tuple.Tuple7[IOResult[T]]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceParTuple8

func SequenceParTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t tuple.Tuple8[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8]]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceParTuple8 converts a [tuple.Tuple8[IOResult[T]]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceParTuple9

func SequenceParTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t tuple.Tuple9[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9]]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceParTuple9 converts a [tuple.Tuple9[IOResult[T]]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceParTuple10

func SequenceParTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t tuple.Tuple10[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9], IOResult[T10]]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceParTuple10 converts a [tuple.Tuple10[IOResult[T]]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func SequenceRecord

func SequenceRecord[K comparable, A any](ma map[K]IOResult[A]) IOResult[map[K]A]

SequenceRecord converts a homogeneous sequence of either into an either of sequence SequenceRecord converts a map of IOResults into an IOResult of a map. Uses parallel execution by default.

func SequenceRecordPar

func SequenceRecordPar[K comparable, A any](ma map[K]IOResult[A]) IOResult[map[K]A]

SequenceRecordPar converts a homogeneous Paruence of either into an either of Paruence SequenceRecordPar converts a map of IOResults in parallel (explicit).

func SequenceRecordSeq

func SequenceRecordSeq[K comparable, A any](ma map[K]IOResult[A]) IOResult[map[K]A]

SequenceRecordSeq converts a homogeneous sequence of either into an either of sequence SequenceRecordSeq converts a map of IOResults sequentially.

func SequenceSeqT1

func SequenceSeqT1[T1 any](
	t1 IOResult[T1],
) IOResult[tuple.Tuple1[T1]]

SequenceSeqT1 converts 1 [IOResult[T]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceSeqT2

func SequenceSeqT2[T1, T2 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
) IOResult[tuple.Tuple2[T1, T2]]

SequenceSeqT2 converts 2 [IOResult[T]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceSeqT3

func SequenceSeqT3[T1, T2, T3 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceSeqT3 converts 3 [IOResult[T]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceSeqT4

func SequenceSeqT4[T1, T2, T3, T4 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceSeqT4 converts 4 [IOResult[T]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceSeqT5

func SequenceSeqT5[T1, T2, T3, T4, T5 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceSeqT5 converts 5 [IOResult[T]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceSeqT6

func SequenceSeqT6[T1, T2, T3, T4, T5, T6 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceSeqT6 converts 6 [IOResult[T]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceSeqT7

func SequenceSeqT7[T1, T2, T3, T4, T5, T6, T7 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceSeqT7 converts 7 [IOResult[T]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceSeqT8

func SequenceSeqT8[T1, T2, T3, T4, T5, T6, T7, T8 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceSeqT8 converts 8 [IOResult[T]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceSeqT9

func SequenceSeqT9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceSeqT9 converts 9 [IOResult[T]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceSeqT10

func SequenceSeqT10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
	t10 IOResult[T10],
) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceSeqT10 converts 10 [IOResult[T]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func SequenceSeqTuple1

func SequenceSeqTuple1[T1 any](t tuple.Tuple1[IOResult[T1]]) IOResult[tuple.Tuple1[T1]]

SequenceSeqTuple1 converts a [tuple.Tuple1[IOResult[T]]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceSeqTuple2

func SequenceSeqTuple2[T1, T2 any](t tuple.Tuple2[IOResult[T1], IOResult[T2]]) IOResult[tuple.Tuple2[T1, T2]]

SequenceSeqTuple2 converts a [tuple.Tuple2[IOResult[T]]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceSeqTuple3

func SequenceSeqTuple3[T1, T2, T3 any](t tuple.Tuple3[IOResult[T1], IOResult[T2], IOResult[T3]]) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceSeqTuple3 converts a [tuple.Tuple3[IOResult[T]]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceSeqTuple4

func SequenceSeqTuple4[T1, T2, T3, T4 any](t tuple.Tuple4[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4]]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceSeqTuple4 converts a [tuple.Tuple4[IOResult[T]]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceSeqTuple5

func SequenceSeqTuple5[T1, T2, T3, T4, T5 any](t tuple.Tuple5[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5]]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceSeqTuple5 converts a [tuple.Tuple5[IOResult[T]]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceSeqTuple6

func SequenceSeqTuple6[T1, T2, T3, T4, T5, T6 any](t tuple.Tuple6[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6]]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceSeqTuple6 converts a [tuple.Tuple6[IOResult[T]]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceSeqTuple7

func SequenceSeqTuple7[T1, T2, T3, T4, T5, T6, T7 any](t tuple.Tuple7[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7]]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceSeqTuple7 converts a [tuple.Tuple7[IOResult[T]]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceSeqTuple8

func SequenceSeqTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t tuple.Tuple8[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8]]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceSeqTuple8 converts a [tuple.Tuple8[IOResult[T]]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceSeqTuple9

func SequenceSeqTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t tuple.Tuple9[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9]]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceSeqTuple9 converts a [tuple.Tuple9[IOResult[T]]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceSeqTuple10

func SequenceSeqTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t tuple.Tuple10[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9], IOResult[T10]]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceSeqTuple10 converts a [tuple.Tuple10[IOResult[T]]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func SequenceT1

func SequenceT1[T1 any](
	t1 IOResult[T1],
) IOResult[tuple.Tuple1[T1]]

SequenceT1 converts 1 [IOResult[T]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceT2

func SequenceT2[T1, T2 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
) IOResult[tuple.Tuple2[T1, T2]]

SequenceT2 converts 2 [IOResult[T]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceT3

func SequenceT3[T1, T2, T3 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceT3 converts 3 [IOResult[T]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceT4

func SequenceT4[T1, T2, T3, T4 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceT4 converts 4 [IOResult[T]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceT5

func SequenceT5[T1, T2, T3, T4, T5 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceT5 converts 5 [IOResult[T]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceT6

func SequenceT6[T1, T2, T3, T4, T5, T6 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceT6 converts 6 [IOResult[T]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceT7

func SequenceT7[T1, T2, T3, T4, T5, T6, T7 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceT7 converts 7 [IOResult[T]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceT8

func SequenceT8[T1, T2, T3, T4, T5, T6, T7, T8 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceT8 converts 8 [IOResult[T]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceT9

func SequenceT9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceT9 converts 9 [IOResult[T]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceT10

func SequenceT10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](
	t1 IOResult[T1],
	t2 IOResult[T2],
	t3 IOResult[T3],
	t4 IOResult[T4],
	t5 IOResult[T5],
	t6 IOResult[T6],
	t7 IOResult[T7],
	t8 IOResult[T8],
	t9 IOResult[T9],
	t10 IOResult[T10],
) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceT10 converts 10 [IOResult[T]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func SequenceTuple1

func SequenceTuple1[T1 any](t tuple.Tuple1[IOResult[T1]]) IOResult[tuple.Tuple1[T1]]

SequenceTuple1 converts a [tuple.Tuple1[IOResult[T]]] into a [IOResult[tuple.Tuple1[T1]]]

func SequenceTuple2

func SequenceTuple2[T1, T2 any](t tuple.Tuple2[IOResult[T1], IOResult[T2]]) IOResult[tuple.Tuple2[T1, T2]]

SequenceTuple2 converts a [tuple.Tuple2[IOResult[T]]] into a [IOResult[tuple.Tuple2[T1, T2]]]

func SequenceTuple3

func SequenceTuple3[T1, T2, T3 any](t tuple.Tuple3[IOResult[T1], IOResult[T2], IOResult[T3]]) IOResult[tuple.Tuple3[T1, T2, T3]]

SequenceTuple3 converts a [tuple.Tuple3[IOResult[T]]] into a [IOResult[tuple.Tuple3[T1, T2, T3]]]

func SequenceTuple4

func SequenceTuple4[T1, T2, T3, T4 any](t tuple.Tuple4[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4]]) IOResult[tuple.Tuple4[T1, T2, T3, T4]]

SequenceTuple4 converts a [tuple.Tuple4[IOResult[T]]] into a [IOResult[tuple.Tuple4[T1, T2, T3, T4]]]

func SequenceTuple5

func SequenceTuple5[T1, T2, T3, T4, T5 any](t tuple.Tuple5[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5]]) IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]

SequenceTuple5 converts a [tuple.Tuple5[IOResult[T]]] into a [IOResult[tuple.Tuple5[T1, T2, T3, T4, T5]]]

func SequenceTuple6

func SequenceTuple6[T1, T2, T3, T4, T5, T6 any](t tuple.Tuple6[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6]]) IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

SequenceTuple6 converts a [tuple.Tuple6[IOResult[T]]] into a [IOResult[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]]

func SequenceTuple7

func SequenceTuple7[T1, T2, T3, T4, T5, T6, T7 any](t tuple.Tuple7[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7]]) IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

SequenceTuple7 converts a [tuple.Tuple7[IOResult[T]]] into a [IOResult[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]]

func SequenceTuple8

func SequenceTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t tuple.Tuple8[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8]]) IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceTuple8 converts a [tuple.Tuple8[IOResult[T]]] into a [IOResult[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func SequenceTuple9

func SequenceTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t tuple.Tuple9[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9]]) IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

SequenceTuple9 converts a [tuple.Tuple9[IOResult[T]]] into a [IOResult[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func SequenceTuple10

func SequenceTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t tuple.Tuple10[IOResult[T1], IOResult[T2], IOResult[T3], IOResult[T4], IOResult[T5], IOResult[T6], IOResult[T7], IOResult[T8], IOResult[T9], IOResult[T10]]) IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]

SequenceTuple10 converts a [tuple.Tuple10[IOResult[T]]] into a [IOResult[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

type Kleisli

type Kleisli[A, B any] = Reader[A, IOResult[B]]

Kleisli represents a function from A to an IOResult of B. It is used for chaining computations that may fail.

func LogJSON

func LogJSON[A any](prefix string) Kleisli[A, any]

LogJSON converts the argument to pretty printed JSON and then logs it via the format string Can be used with ChainFirst

func TraverseArray

func TraverseArray[A, B any](f Kleisli[A, B]) Kleisli[[]A, []B]

TraverseArray transforms an array TraverseArray transforms an array by applying an IOResult-producing function to each element. Uses parallel execution by default. If any element fails, the entire traversal fails.

func TraverseArrayPar

func TraverseArrayPar[A, B any](f Kleisli[A, B]) Kleisli[[]A, []B]

TraverseArrayPar transforms an array TraverseArrayPar transforms an array in parallel (explicit). This is equivalent to TraverseArray but makes parallelism explicit.

func TraverseArraySeq

func TraverseArraySeq[A, B any](f Kleisli[A, B]) Kleisli[[]A, []B]

TraverseArraySeq transforms an array TraverseArraySeq transforms an array sequentially. Elements are processed one at a time in order.

func TraverseArrayWithIndex

func TraverseArrayWithIndex[A, B any](f func(int, A) IOResult[B]) Kleisli[[]A, []B]

TraverseArrayWithIndex transforms an array TraverseArrayWithIndex transforms an array with access to element indices. Uses parallel execution by default.

func TraverseArrayWithIndexPar

func TraverseArrayWithIndexPar[A, B any](f func(int, A) IOResult[B]) Kleisli[[]A, []B]

TraverseArrayWithIndexPar transforms an array TraverseArrayWithIndexPar transforms an array in parallel with indices (explicit).

func TraverseArrayWithIndexSeq

func TraverseArrayWithIndexSeq[A, B any](f func(int, A) IOResult[B]) Kleisli[[]A, []B]

TraverseArrayWithIndexSeq transforms an array TraverseArrayWithIndexSeq transforms an array sequentially with indices.

func TraverseRecord

func TraverseRecord[K comparable, A, B any](f Kleisli[A, B]) Kleisli[map[K]A, map[K]B]

TraverseRecord transforms a record TraverseRecord transforms a map by applying an IOResult-producing function to each value. Uses parallel execution by default.

func TraverseRecordPar

func TraverseRecordPar[K comparable, A, B any](f Kleisli[A, B]) Kleisli[map[K]A, map[K]B]

TraverseRecordPar transforms a record TraverseRecordPar transforms a map in parallel (explicit).

func TraverseRecordSeq

func TraverseRecordSeq[K comparable, A, B any](f Kleisli[A, B]) Kleisli[map[K]A, map[K]B]

TraverseRecordSeq transforms a record TraverseRecordSeq transforms a map sequentially.

func TraverseRecordWithIndex

func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) IOResult[B]) Kleisli[map[K]A, map[K]B]

TraverseRecordWithIndex transforms a record TraverseRecordWithIndex transforms a map with access to keys. Uses parallel execution by default.

func TraverseRecordWithIndexPar

func TraverseRecordWithIndexPar[K comparable, A, B any](f func(K, A) IOResult[B]) Kleisli[map[K]A, map[K]B]

TraverseRecordWithIndexPar transforms a record TraverseRecordWithIndexPar transforms a map in parallel with keys (explicit).

func TraverseRecordWithIndexSeq

func TraverseRecordWithIndexSeq[K comparable, A, B any](f func(K, A) IOResult[B]) Kleisli[map[K]A, map[K]B]

TraverseRecordWithIndexSeq transforms a record TraverseRecordWithIndexSeq transforms a map sequentially with keys.

func WithResource

func WithResource[A, R, ANY any](
	onCreate IOResult[R],
	onRelease Kleisli[R, ANY],
) Kleisli[Kleisli[R, A], A]

WithResource constructs a function that creates a resource, then operates on it and then releases the resource WithResource constructs a bracket pattern for resource management. It ensures resources are properly acquired, used, and released even if errors occur. The release function is always called, similar to defer.

type Lazy

type Lazy[A any] = lazy.Lazy[A]

Lazy represents a deferred computation that produces a value of type A when evaluated.

type Monoid

type Monoid[A any] = monoid.Monoid[IOResult[A]]

func ApplicativeMonoid

func ApplicativeMonoid[A any](
	m monoid.Monoid[A],
) Monoid[A]

ApplicativeMonoid returns a Monoid that concatenates [IOEither] instances via their applicative ApplicativeMonoid returns a Monoid that concatenates IOResult instances via their applicative. Uses parallel execution (default Ap behavior).

func ApplicativeMonoidPar

func ApplicativeMonoidPar[A any](
	m monoid.Monoid[A],
) Monoid[A]

ApplicativeMonoid returns a Monoid that concatenates [IOEither] instances via their applicative ApplicativeMonoidPar returns a Monoid that concatenates IOResult instances in parallel. Uses parallel execution (ApPar) explicitly.

func ApplicativeMonoidSeq

func ApplicativeMonoidSeq[A any](
	m monoid.Monoid[A],
) Monoid[A]

ApplicativeMonoid returns a Monoid that concatenates [IOEither] instances via their applicative ApplicativeMonoidSeq returns a Monoid that concatenates IOResult instances sequentially. Uses sequential execution (ApSeq).

type Operator

type Operator[A, B any] = Kleisli[IOResult[A], B]

Operator represents a transformation from IOResult[A] to IOResult[B]. It is commonly used in function composition pipelines.

func After

func After[A any](timestamp time.Time) Operator[A, A]

After creates an operator that delays execution until the specified timestamp. If the timestamp is in the past, the IOResult executes immediately.

func Alt

func Alt[A any](second Lazy[IOResult[A]]) Operator[A, A]

Alt returns an operator that provides a fallback for error recovery. This identifies an associative operation on a type constructor for the Alternative instance.

func Ap

func Ap[B, A any](ma IOResult[A]) Operator[func(A) B, B]

Ap returns an operator that applies a function in IOResult context. This enables applicative-style programming with IOResult values.

func ApFirst

func ApFirst[A, B any](second IOResult[B]) Operator[A, A]

ApFirst combines two effectful actions, keeping only the result of the first.

func ApPar

func ApPar[B, A any](ma IOResult[A]) Operator[func(A) B, B]

ApPar returns an operator that applies a function to a value in parallel. This is the operator form of MonadApPar.

func ApS

func ApS[S1, S2, T any](
	setter func(T) func(S1) S2,
	fa IOResult[T],
) Operator[S1, S2]

ApS applies an IOResult to extend the state in do-notation. This is used to add independent computations that don't depend on previous results.

func ApSL

func ApSL[S, T any](
	lens L.Lens[S, T],
	fa IOResult[T],
) Operator[S, S]

ApSL applies an IOResult using a lens to update a specific field in the state.

func ApSecond

func ApSecond[A, B any](second IOResult[B]) Operator[A, B]

ApSecond combines two effectful actions, keeping only the result of the second.

func BiMap

func BiMap[A, B any](f Endomorphism[error], g func(A) B) Operator[A, B]

BiMap returns an operator that transforms both error and success values. This is the Bifunctor map operation for IOResult.

func Bind

func Bind[S1, S2, T any](
	setter func(T) func(S1) S2,
	f Kleisli[S1, T],
) Operator[S1, S2]

Bind adds a computation step in do-notation, extending the state with a new field. The setter function determines how the new value is added to the state.

func BindL

func BindL[S, T any](
	lens L.Lens[S, T],
	f Kleisli[T, T],
) Operator[S, S]

BindL binds a computation using a lens to focus on a specific field.

func BindTo

func BindTo[S1, T any](
	setter func(T) S1,
) Operator[T, S1]

BindTo wraps a value in an initial state structure. This is typically the first operation after creating an IOResult in do-notation.

func Chain

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

Chain returns an operator that chains a kleisli function. This enables dependent computations where the next step depends on the previous result.

func ChainEitherK

func ChainEitherK[A, B any](f either.Kleisli[error, A, B]) Operator[A, B]

ChainEitherK returns an operator that chains a function returning Either. Either's Left becomes an error, Right becomes a successful value.

func ChainFirst

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

ChainFirst returns an operator that runs a computation for side effects but keeps the original value. This is useful for operations like validation or logging.

func ChainFirstEitherK

func ChainFirstEitherK[A, B any](f either.Kleisli[error, A, B]) Operator[A, A]

ChainFirstEitherK returns an operator that runs an Either computation for side effects. This is useful for validation that may fail.

func ChainFirstIOK

func ChainFirstIOK[A, B any](f io.Kleisli[A, B]) Operator[A, A]

ChainFirstIOK returns an operator that runs an IO computation for side effects. This is useful for operations like logging that cannot fail.

func ChainFirstLeft

func ChainFirstLeft[A, B any](f Kleisli[error, B]) Operator[A, A]

ChainFirstLeft returns an operator that runs a computation on errors for side effects. The original error is always preserved.

func ChainFirstResultK

func ChainFirstResultK[A, B any](f result.Kleisli[A, B]) Operator[A, A]

ChainFirstResultK returns an operator that runs a Result computation for side effects. This integrates with standard Go error-returning functions.

func ChainIOK

func ChainIOK[A, B any](f io.Kleisli[A, B]) Operator[A, B]

ChainIOK returns an operator that chains an IO kleisli function to an IOResult. The IO computation is wrapped in a successful IOResult context.

func ChainLazyK

func ChainLazyK[A, B any](f func(A) Lazy[B]) Operator[A, B]

ChainLazyK returns an operator that chains a lazy computation to an IOResult. This is an alias for ChainIOK since Lazy and IO are equivalent.

func ChainLeft

func ChainLeft[A any](f Kleisli[error, A]) Operator[A, A]

ChainLeft returns an operator that handles errors with a recovery computation. This enables error recovery and transformation.

func ChainResultK

func ChainResultK[A, B any](f result.Kleisli[A, B]) Operator[A, B]

ChainResultK returns an operator that chains a function returning (value, error). This enables integration with standard Go error handling patterns.

func ChainTo

func ChainTo[A, B any](fb IOResult[B]) Operator[A, B]

ChainTo returns an operator that sequences two computations, keeping only the second result. This is the operator form of MonadChainTo.

func Delay

func Delay[A any](delay time.Duration) Operator[A, A]

Delay creates an operator that delays execution by the specified duration. The IOResult is executed after waiting for the given duration.

func FilterOrElse added in v2.1.0

func FilterOrElse[A any](pred Predicate[A], onFalse func(A) error) Operator[A, A]

FilterOrElse filters an IOResult value based on a predicate in an idiomatic style. If the IOResult computation succeeds and the predicate returns true, returns the original success value. If the IOResult computation succeeds and the predicate returns false, returns an error with the error from onFalse. If the IOResult computation fails, returns the original error without applying the predicate.

This is the idiomatic version that returns an Operator for use in method chaining. It's useful for adding validation to successful IO computations, converting them to errors if they don't meet certain criteria.

Example:

import (
	IO "github.com/IBM/fp-go/v2/idiomatic/ioresult"
	N "github.com/IBM/fp-go/v2/number"
)

isPositive := N.MoreThan(0)
onNegative := func(x int) error { return fmt.Errorf("%d is not positive", x) }

result := IO.Of(5).
	Pipe(IO.FilterOrElse(isPositive, onNegative))() // Ok(5)

result2 := IO.Of(-3).
	Pipe(IO.FilterOrElse(isPositive, onNegative))() // Error(error: "-3 is not positive")

func Flap

func Flap[B, A any](a A) Operator[func(A) B, B]

Flap returns an operator that applies a fixed argument to a wrapped function. This is useful for partial application with wrapped functions.

func Let

func Let[S1, S2, T any](
	setter func(T) func(S1) S2,
	f func(S1) T,
) Operator[S1, S2]

Let adds a pure transformation step in do-notation. Unlike Bind, the function does not return an IOResult, making it suitable for pure computations.

func LetL

func LetL[S, T any](
	lens L.Lens[S, T],
	f func(T) T,
) Operator[S, S]

LetL applies a pure transformation using a lens to update a specific field.

func LetTo

func LetTo[S1, S2, T any](
	setter func(T) func(S1) S2,
	b T,
) Operator[S1, S2]

LetTo adds a constant value to the state in do-notation.

func LetToL

func LetToL[S, T any](
	lens L.Lens[S, T],
	b T,
) Operator[S, S]

LetToL sets a field to a constant value using a lens.

func Map

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

Map returns an operator that transforms values using the given function. This is the Functor map operation for IOResult.

func MapLeft

func MapLeft[A any](f Endomorphism[error]) Operator[A, A]

MapLeft returns an operator that transforms the error using the given function. This is useful for error wrapping or enrichment.

func MapTo

func MapTo[A, B any](b B) Operator[A, B]

MapTo returns an operator that replaces the value with a constant. This is useful for discarding the result while keeping the computational context.

func Tap

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

Tap returns an operator that executes side effects while preserving the original value. This is an alias for ChainFirst.

func TapEitherK

func TapEitherK[A, B any](f either.Kleisli[error, A, B]) Operator[A, A]

TapEitherK returns an operator that executes an Either computation for side effects. This is an alias for ChainFirstEitherK.

func TapIOK

func TapIOK[A, B any](f io.Kleisli[A, B]) Operator[A, A]

TapIOK returns an operator that executes an IO computation for side effects. This is an alias for ChainFirstIOK.

func TapLeft

func TapLeft[A, B any](f Kleisli[error, B]) Operator[A, A]

TapLeft returns an operator that executes side effects on errors. This is an alias for ChainFirstLeft.

func TapResultK

func TapResultK[A, B any](f result.Kleisli[A, B]) Operator[A, A]

TapResultK returns an operator that executes a Result computation for side effects. This is an alias for ChainFirstResultK.

func WithLock

func WithLock[A any](lock IO[context.CancelFunc]) Operator[A, A]

WithLock executes the provided IO operation in the scope of a lock WithLock executes an IOResult within the scope of a lock. The lock is acquired before execution and released after (via defer).

type Predicate added in v2.1.0

type Predicate[A any] = predicate.Predicate[A]

type Reader

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

Reader represents a computation that depends on a read-only environment of type R and produces a value of type A.

type Result

type Result[A any] = result.Result[A]

Result represents an Either with error as the left type, compatible with Go's (value, error) tuple.

type Semigroup

type Semigroup[A any] = semigroup.Semigroup[IOResult[A]]

func AltSemigroup

func AltSemigroup[A any]() Semigroup[A]

AltSemigroup is a Semigroup that tries the first item and then the second one using an alternative AltSemigroup creates a Semigroup that tries the first IOResult, then the second on failure. This implements the alternative operation for combining IOResults.

type Void added in v2.2.2

type Void = function.Void

Directories

Path Synopsis
Package exec provides utilities for executing system commands with IOResult-based error handling.
Package exec provides utilities for executing system commands with IOResult-based error handling.

Jump to

Keyboard shortcuts

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