iooption

package
v2.1.13 Latest Latest
Warning

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

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

Documentation

Overview

Package iooption provides the IOOption monad, combining IO effects with Option for optional values.

Fantasy Land Specification

This is a monad transformer combining:

Implemented Fantasy Land algebras:

IOOption[A] represents a computation that:

  • Performs side effects (IO)
  • May or may not produce a value of type A (Option)

This is defined as: IO[Option[A]] or func() Option[A]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eq

func Eq[A any](eq EQ.Eq[A]) EQ.Eq[IOOption[A]]

Eq implements the equals predicate for values contained in the IO monad

func Fold

func Fold[A, B any](onNone IO[B], onSome io.Kleisli[A, B]) func(IOOption[A]) IO[B]

Fold convers an IOOption into an IO

func FromStrictEquals

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

FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function

func Optionize2

func Optionize2[T1, T2, A any](f func(t1 T1, t2 T2) (A, bool)) func(T1, T2) IOOption[A]

func Optionize3

func Optionize3[T1, T2, T3, A any](f func(t1 T1, t2 T2, t3 T3) (A, bool)) func(T1, T2, T3) IOOption[A]

func Optionize4

func Optionize4[T1, T2, T3, T4, A any](f func(t1 T1, t2 T2, t3 T3, t4 T4) (A, bool)) func(T1, T2, T3, T4) IOOption[A]

func TraverseParTuple10

func TraverseParTuple10[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, T9], F10 ~Kleisli[A10, 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]) IOOption[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 [IOOption[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func TraverseParTuple2

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

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

func TraverseParTuple3

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

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

func TraverseParTuple4

func TraverseParTuple4[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, 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]) IOOption[tuple.Tuple4[T1, T2, T3, T4]]

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

func TraverseParTuple5

func TraverseParTuple5[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, 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]) IOOption[tuple.Tuple5[T1, T2, T3, T4, T5]]

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

func TraverseParTuple6

func TraverseParTuple6[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, 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]) IOOption[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

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

func TraverseParTuple7

func TraverseParTuple7[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, 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]) IOOption[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

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

func TraverseParTuple8

func TraverseParTuple8[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, 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]) IOOption[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 [IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseParTuple9

func TraverseParTuple9[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, 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]) IOOption[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 [IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func TraverseSeqTuple10

func TraverseSeqTuple10[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, T9], F10 ~Kleisli[A10, 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]) IOOption[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 [IOOption[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func TraverseSeqTuple2

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

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

func TraverseSeqTuple3

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

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

func TraverseSeqTuple4

func TraverseSeqTuple4[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, 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]) IOOption[tuple.Tuple4[T1, T2, T3, T4]]

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

func TraverseSeqTuple5

func TraverseSeqTuple5[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, 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]) IOOption[tuple.Tuple5[T1, T2, T3, T4, T5]]

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

func TraverseSeqTuple6

func TraverseSeqTuple6[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, 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]) IOOption[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

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

func TraverseSeqTuple7

func TraverseSeqTuple7[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, 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]) IOOption[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

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

func TraverseSeqTuple8

func TraverseSeqTuple8[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, 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]) IOOption[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 [IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseSeqTuple9

func TraverseSeqTuple9[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, 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]) IOOption[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 [IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func TraverseTuple10

func TraverseTuple10[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, T9], F10 ~Kleisli[A10, 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]) IOOption[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 [IOOption[tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]]

func TraverseTuple2

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

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

func TraverseTuple3

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

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

func TraverseTuple4

func TraverseTuple4[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, 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]) IOOption[tuple.Tuple4[T1, T2, T3, T4]]

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

func TraverseTuple5

func TraverseTuple5[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, 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]) IOOption[tuple.Tuple5[T1, T2, T3, T4, T5]]

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

func TraverseTuple6

func TraverseTuple6[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, 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]) IOOption[tuple.Tuple6[T1, T2, T3, T4, T5, T6]]

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

func TraverseTuple7

func TraverseTuple7[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, 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]) IOOption[tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]]

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

func TraverseTuple8

func TraverseTuple8[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, 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]) IOOption[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 [IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]]

func TraverseTuple9

func TraverseTuple9[F1 ~Kleisli[A1, T1], F2 ~Kleisli[A2, T2], F3 ~Kleisli[A3, T3], F4 ~Kleisli[A4, T4], F5 ~Kleisli[A5, T5], F6 ~Kleisli[A6, T6], F7 ~Kleisli[A7, T7], F8 ~Kleisli[A8, T8], F9 ~Kleisli[A9, 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]) IOOption[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 [IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]]

func WithLock

func WithLock[E, A any](lock IO[context.CancelFunc]) func(fa IOOption[A]) IOOption[A]

WithLock executes the provided IO operation in the scope of a lock

Types

type Consumer

type Consumer[A any] = consumer.Consumer[A]

Consumer represents a function that consumes a value of type A. It's typically used for side effects like logging or updating state.

type Either

type Either[E, A any] = either.Either[E, A]

Either represents a value of one of two possible types (a disjoint union).

type IO

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

IO represents a synchronous computation that cannot fail.

type IOOption

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

IOOption represents a synchronous computation that may not produce a value. It combines IO (side effects) with Option (optional values). Refer to [https://andywhite.xyz/posts/2021-01-27-rte-foundations/#ioeitherlte-agt] for more details.

func Bracket

func Bracket[A, B, ANY any](
	acquire IOOption[A],
	use Kleisli[A, B],
	release func(A, Option[B]) IOOption[ANY],
) IOOption[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 func() IOOption[A]) IOOption[A]

Defer creates an IO by creating a brand new IO via a generator function, each time

func Do

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

Do creates an empty context of type [S] to be used with the Bind operation. This is the starting point for do-notation style composition.

Example:

type State struct {
    Name  string
    Age   int
}
result := iooption.Do(State{})

func Flatten

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

func FromEither

func FromEither[E, A any](e Either[E, A]) IOOption[A]

FromEither converts an Either into an IOOption

func FromIO

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

func FromOption

func FromOption[A any](o Option[A]) IOOption[A]

func Memoize

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

func MonadAlt

func MonadAlt[A any](first, second IOOption[A]) IOOption[A]

MonadAlt identifies an associative operation on a type constructor

func MonadAp

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

func MonadChain

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

func MonadChainFirst

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

MonadChainFirst runs the monad returned by the function but returns the result of the original monad

func MonadChainFirstIOK

func MonadChainFirstIOK[A, B any](first IOOption[A], f io.Kleisli[A, B]) IOOption[A]

MonadChainFirstIOK runs the monad returned by the function but returns the result of the original monad

func MonadChainIOK

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

func MonadMap

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

func MonadOf

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

func None

func None[A any]() IOOption[A]

func Of

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

func Retrying

func Retrying[A any](
	policy R.RetryPolicy,
	action Kleisli[R.RetryStatus, A],
	check Predicate[A],
) IOOption[A]

Retrying will retry the actions according to the check policy

func SequenceArray

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

SequenceArray converts a homogeneous sequence of either into an either of sequence

func SequenceParT1

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

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

func SequenceParT10

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

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

func SequenceParT2

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

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

func SequenceParT3

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

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

func SequenceParT4

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

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

func SequenceParT5

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

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

func SequenceParT6

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

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

func SequenceParT7

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

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

func SequenceParT8

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

SequenceParT8 converts 8 [IOOption[T]] into a [IOOption[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 IOOption[T1],
	t2 IOOption[T2],
	t3 IOOption[T3],
	t4 IOOption[T4],
	t5 IOOption[T5],
	t6 IOOption[T6],
	t7 IOOption[T7],
	t8 IOOption[T8],
	t9 IOOption[T9],
) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func SequenceParTuple1

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

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

func SequenceParTuple10

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

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

func SequenceParTuple2

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

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

func SequenceParTuple3

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

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

func SequenceParTuple4

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

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

func SequenceParTuple5

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

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

func SequenceParTuple6

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

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

func SequenceParTuple7

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

SequenceParTuple7 converts a [tuple.Tuple7[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8]]) IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceParTuple8 converts a [tuple.Tuple8[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8], IOOption[T9]]) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func SequenceSeqT1

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

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

func SequenceSeqT10

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

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

func SequenceSeqT2

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

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

func SequenceSeqT3

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

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

func SequenceSeqT4

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

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

func SequenceSeqT5

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

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

func SequenceSeqT6

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

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

func SequenceSeqT7

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

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

func SequenceSeqT8

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

SequenceSeqT8 converts 8 [IOOption[T]] into a [IOOption[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 IOOption[T1],
	t2 IOOption[T2],
	t3 IOOption[T3],
	t4 IOOption[T4],
	t5 IOOption[T5],
	t6 IOOption[T6],
	t7 IOOption[T7],
	t8 IOOption[T8],
	t9 IOOption[T9],
) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func SequenceSeqTuple1

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

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

func SequenceSeqTuple10

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

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

func SequenceSeqTuple2

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

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

func SequenceSeqTuple3

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

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

func SequenceSeqTuple4

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

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

func SequenceSeqTuple5

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

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

func SequenceSeqTuple6

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

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

func SequenceSeqTuple7

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

SequenceSeqTuple7 converts a [tuple.Tuple7[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8]]) IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceSeqTuple8 converts a [tuple.Tuple8[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8], IOOption[T9]]) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func SequenceT1

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

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

func SequenceT10

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

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

func SequenceT2

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

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

func SequenceT3

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

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

func SequenceT4

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

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

func SequenceT5

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

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

func SequenceT6

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

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

func SequenceT7

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

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

func SequenceT8

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

SequenceT8 converts 8 [IOOption[T]] into a [IOOption[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 IOOption[T1],
	t2 IOOption[T2],
	t3 IOOption[T3],
	t4 IOOption[T4],
	t5 IOOption[T5],
	t6 IOOption[T6],
	t7 IOOption[T7],
	t8 IOOption[T8],
	t9 IOOption[T9],
) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func SequenceTuple1

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

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

func SequenceTuple10

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

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

func SequenceTuple2

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

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

func SequenceTuple3

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

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

func SequenceTuple4

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

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

func SequenceTuple5

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

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

func SequenceTuple6

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

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

func SequenceTuple7

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

SequenceTuple7 converts a [tuple.Tuple7[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8]]) IOOption[tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]

SequenceTuple8 converts a [tuple.Tuple8[IOOption[T]]] into a [IOOption[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[IOOption[T1], IOOption[T2], IOOption[T3], IOOption[T4], IOOption[T5], IOOption[T6], IOOption[T7], IOOption[T8], IOOption[T9]]) IOOption[tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]

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

func Some

func Some[A any](r A) IOOption[A]

type Kleisli

type Kleisli[A, B any] = reader.Reader[A, IOOption[B]]

Kleisli represents a Kleisli arrow for the IOOption monad. It's a function from A to IOOption[B], used for composing operations that may not produce a value.

func Optionize1

func Optionize1[T1, A any](f func(t1 T1) (A, bool)) Kleisli[T1, A]

func TailRec

func TailRec[A, B any](f Kleisli[A, tailrec.Trampoline[A, B]]) Kleisli[A, B]

TailRec creates a tail-recursive computation in the IOOption monad. It enables writing recursive algorithms that don't overflow the call stack by using an iterative loop - a technique where recursive calls are converted into iterations.

The function takes a step function that returns an IOOption containing a Trampoline:

  • None: Terminate recursion with no result
  • Some(Bounce(A)): Continue recursion with a new value of type A
  • Some(Land(B)): Terminate recursion with a final result of type B

This is particularly useful for implementing recursive algorithms that may fail at any step:

  • Iterative calculations that may not produce a result
  • State machines with multiple steps that can fail
  • Loops that may terminate early with None
  • Processing collections with optional results

Unlike the IOEither version which uses lazy recursion, this implementation uses an explicit iterative loop for better performance and simpler control flow.

Type Parameters:

  • E: Unused type parameter (kept for consistency with IOEither)
  • A: The intermediate type used during recursion (loop state)
  • B: The final result type when recursion terminates successfully

Parameters:

  • f: A step function that takes the current state (A) and returns an IOOption containing either None (failure), Some(Bounce(A)) to continue with a new state, or Some(Land(B)) to terminate with a final result

Returns:

  • A Kleisli arrow (function from A to IOOption[B]) that executes the tail-recursive computation starting from the initial value

Example - Computing factorial with optional result:

type FactState struct {
    n      int
    result int
}

factorial := TailRec[any](func(state FactState) IOOption[tailrec.Trampoline[FactState, int]] {
    if state.n < 0 {
        // Negative numbers have no factorial
        return None[tailrec.Trampoline[FactState, int]]()
    }
    if state.n <= 1 {
        // Terminate with final result
        return Of(tailrec.Land[FactState](state.result))
    }
    // Continue with next iteration
    return Of(tailrec.Bounce[int](FactState{
        n:      state.n - 1,
        result: state.result * state.n,
    }))
})

result := factorial(FactState{n: 5, result: 1})() // Some(120)
result := factorial(FactState{n: -1, result: 1})() // None

Example - Safe division with early termination:

type DivState struct {
    numerator   int
    denominator int
    steps       int
}

safeDivide := TailRec[any](func(state DivState) IOOption[tailrec.Trampoline[DivState, int]] {
    if state.denominator == 0 {
        return None[tailrec.Trampoline[DivState, int]]() // Division by zero
    }
    if state.numerator < state.denominator {
        return Of(tailrec.Land[DivState](state.steps))
    }
    return Of(tailrec.Bounce[int](DivState{
        numerator:   state.numerator - state.denominator,
        denominator: state.denominator,
        steps:       state.steps + 1,
    }))
})

result := safeDivide(DivState{numerator: 10, denominator: 3, steps: 0})() // Some(3)
result := safeDivide(DivState{numerator: 10, denominator: 0, steps: 0})() // None

func TraverseArray

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

TraverseArray transforms an array

func TraverseArrayWithIndex

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

TraverseArrayWithIndex transforms an array

func TraverseParTuple1

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

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

func TraverseSeqTuple1

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

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

func TraverseTuple1

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

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

func WithResource

func WithResource[
	R, A, ANY any](onCreate IOOption[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

type Lazy

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

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

func Optionize0

func Optionize0[A any](f func() (A, bool)) Lazy[IOOption[A]]

type Lens

type Lens[S, T any] = lens.Lens[S, T]

Lens is an optic that focuses on a field of type T within a structure of type S.

type Operator

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

Operator represents a function that transforms one IOOption into another. It takes an IOOption[A] and produces an IOOption[B].

func After

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

After creates an operation that passes after the given time.Time

func Alt

func Alt[A any](second IOOption[A]) Operator[A, A]

Alt identifies an associative operation on a type constructor

func Ap

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

func ApPar

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

func ApS

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

ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently (using Applicative rather than Monad). This allows independent computations to be combined without one depending on the result of the other.

Unlike Bind, which sequences operations, ApS can be used when operations are independent and can conceptually run in parallel.

Example:

type State struct {
    Name  string
    Age   int
}

// These operations are independent and can be combined with ApS
getName := iooption.Some("Alice")
getAge := iooption.Some(30)

result := F.Pipe2(
    iooption.Do(State{}),
    iooption.ApS(
        func(name string) func(State) State {
            return func(s State) State { s.Name = name; return s }
        },
        getName,
    ),
    iooption.ApS(
        func(age int) func(State) State {
            return func(s State) State { s.Age = age; return s }
        },
        getAge,
    ),
)

func ApSL

func ApSL[S, T any](
	lens Lens[S, T],
	fa IOOption[T],
) Operator[S, S]

ApSL attaches a value to a context using a lens-based setter. This is a convenience function that combines ApS with a lens, allowing you to use optics to update nested structures in a more composable way.

The lens parameter provides both the getter and setter for a field within the structure S. This eliminates the need to manually write setter functions.

Example:

type State struct {
    Name  string
    Age   int
}

ageLens := lens.MakeLens(
    func(s State) int { return s.Age },
    func(s State, a int) State { s.Age = a; return s },
)

result := F.Pipe2(
    iooption.Of(State{Name: "Alice"}),
    iooption.ApSL(ageLens, iooption.Some(30)),
)

func ApSeq

func ApSeq[B, A any](ma IOOption[A]) Operator[func(A) B, B]

func Bind

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

Bind attaches the result of a computation to a context [S1] to produce a context [S2]. This enables sequential composition where each step can depend on the results of previous steps.

The setter function takes the result of the computation and returns a function that updates the context from S1 to S2.

Example:

type State struct {
    Name  string
    Age   int
}

result := F.Pipe2(
    iooption.Do(State{}),
    iooption.Bind(
        func(name string) func(State) State {
            return func(s State) State { s.Name = name; return s }
        },
        func(s State) iooption.IOOption[string] {
            return iooption.FromIO(io.Of("Alice"))
        },
    ),
    iooption.Bind(
        func(age int) func(State) State {
            return func(s State) State { s.Age = age; return s }
        },
        func(s State) iooption.IOOption[int] {
            // This can access s.Name from the previous step
            return iooption.FromIO(io.Of(len(s.Name) * 10))
        },
    ),
)

func BindL

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

BindL attaches the result of a computation to a context using a lens-based setter. This is a convenience function that combines Bind with a lens, allowing you to use optics to update nested structures based on their current values.

The lens parameter provides both the getter and setter for a field within the structure S. The computation function f receives the current value of the focused field and returns an IOOption that produces the new value.

Example:

type Counter struct {
    Value int
}

valueLens := lens.MakeLens(
    func(c Counter) int { return c.Value },
    func(c Counter, v int) Counter { c.Value = v; return c },
)

// Increment the counter, but return None if it would exceed 100
increment := func(v int) iooption.IOOption[int] {
    return iooption.FromIO(io.Of(v + 1))
}

result := F.Pipe1(
    iooption.Of(Counter{Value: 42}),
    iooption.BindL(valueLens, increment),
) // IOOption[Counter{Value: 43}]

func BindTo

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

BindTo initializes a new state [S1] from a value [T]

func BindToP

func BindToP[S1, T any](
	setter Prism[S1, T],
) Operator[T, S1]

func Chain

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

func ChainConsumer

func ChainConsumer[A any](c Consumer[A]) Operator[A, struct{}]

func ChainFirst

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

ChainFirst runs the monad returned by the function but returns the result of the original monad

func ChainFirstConsumer

func ChainFirstConsumer[A any](c Consumer[A]) Operator[A, A]

func ChainFirstIOK

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

ChainFirstIOK runs the monad returned by the function but returns the result of the original monad

func ChainIOK

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

func ChainOptionK

func ChainOptionK[A, B any](f func(A) Option[B]) Operator[A, B]

func Delay

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

Delay creates an operation that passes in the value after some delay

func Let

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

Let attaches the result of a computation to a context [S1] to produce a context [S2]

func LetL

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

LetL attaches the result of a pure computation to a context using a lens-based setter. This is a convenience function that combines Let with a lens, allowing you to use optics to update nested structures with pure transformations.

The lens parameter provides both the getter and setter for a field within the structure S. The transformation function f receives the current value of the focused field and returns the new value directly (not wrapped in IOOption).

Example:

type Counter struct {
    Value int
}

valueLens := lens.MakeLens(
    func(c Counter) int { return c.Value },
    func(c Counter, v int) Counter { c.Value = v; return c },
)

// Double the counter value
double := func(v int) int { return v * 2 }

result := F.Pipe1(
    iooption.Of(Counter{Value: 21}),
    iooption.LetL(valueLens, double),
) // IOOption[Counter{Value: 42}]

func LetTo

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

LetTo attaches the a value to a context [S1] to produce a context [S2]

func LetToL

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

LetToL attaches a constant value to a context using a lens-based setter. This is a convenience function that combines LetTo with a lens, allowing you to use optics to set nested fields to specific values.

The lens parameter provides the setter for a field within the structure S. Unlike LetL which transforms the current value, LetToL simply replaces it with the provided constant value b.

Example:

type Config struct {
    Debug   bool
    Timeout int
}

debugLens := lens.MakeLens(
    func(c Config) bool { return c.Debug },
    func(c Config, d bool) Config { c.Debug = d; return c },
)

result := F.Pipe1(
    iooption.Of(Config{Debug: true, Timeout: 30}),
    iooption.LetToL(debugLens, false),
) // IOOption[Config{Debug: false, Timeout: 30}]

func Map

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

type Option

type Option[A any] = option.Option[A]

Option represents an optional value that may or may not be present.

type Predicate added in v2.1.0

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

Predicate represents a function that tests a value of type A and returns a boolean. It's commonly used for filtering and conditional operations.

type Prism

type Prism[S, T any] = prism.Prism[S, T]

Prism is an optic that focuses on a case of a sum type.

type Trampoline added in v2.1.0

type Trampoline[B, L any] = tailrec.Trampoline[B, L]

Trampoline represents a tail-recursive computation that can be evaluated safely without stack overflow. It's used for implementing stack-safe recursive algorithms.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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