Help us shape the future of Go! Take the 2026 Go Developer Survey

readert

package
v2.10.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ap

func Ap[GEA ~func(E) HKTA, GEB ~func(E) HKTB, GEFAB ~func(E) HKTFAB, E, A, HKTA, HKTB, HKTFAB any](
	fap apply.ApType[HKTA, HKTB, HKTFAB],
	fa GEA) func(GEFAB) GEB

func ApplicativeMonoid added in v2.1.20

func ApplicativeMonoid[R, A any](
	_of func(A) func(R) A,
	_map functor.MapType[A, func(A) A, func(R) A, func(R) func(A) A],
	_ap apply.ApType[func(R) A, func(R) A, func(R) func(A) A],

	m M.Monoid[A],
) M.Monoid[func(R) A]

ApplicativeMonoid lifts a Monoid[A] into a Monoid[Reader[R, A]]. This allows you to combine Readers that produce monoid values, with an empty/identity Reader.

The _of parameter is the Of operation (pure/return) for the Reader type. The _map and _ap parameters are the curried Map and Ap operations for the Reader type.

Example:

type Config struct { Prefix string }
// Using the string concatenation monoid
stringMonoid := monoid.MakeMonoid(func(a, b string) string { return a + b }, "")
readerMonoid := readert.ApplicativeMonoid(
    reader.Of[Config, string],
    reader.Map[Config, string, func(string) string],
    reader.Ap[string, Config, string],
    stringMonoid,
)

r1 := reader.Asks(func(c Config) string { return c.Prefix })
r2 := reader.Of[Config]("hello")
combined := readerMonoid.Concat(r1, r2)
result := combined(Config{Prefix: ">> "}) // ">> hello"
empty := readerMonoid.Empty()(Config{Prefix: "any"}) // ""

func ApplySemigroup added in v2.1.20

func ApplySemigroup[R, A any](
	_map functor.MapType[A, func(A) A, func(R) A, func(R) func(A) A],
	_ap apply.ApType[func(R) A, func(R) A, func(R) func(A) A],

	s S.Semigroup[A],
) S.Semigroup[func(R) A]

ApplySemigroup lifts a Semigroup[A] into a Semigroup[Reader[R, A]]. This allows you to combine two Readers that produce semigroup values by combining their results using the semigroup's concat operation.

The _map and _ap parameters are the curried Map and Ap operations for the Reader type, typically obtained from the reader package.

Example:

type Config struct { Multiplier int }
// Using the additive semigroup for integers
intSemigroup := semigroup.MakeSemigroup(func(a, b int) int { return a + b })
readerSemigroup := readert.ApplySemigroup(
    reader.Map[Config, int, func(int) int],
    reader.Ap[int, Config, int],
    intSemigroup,
)

r1 := reader.Of[Config](5)
r2 := reader.Of[Config](3)
combined := readerSemigroup.Concat(r1, r2)
result := combined(Config{Multiplier: 1}) // 8

func Chain

func Chain[GEA ~func(E) HKTA, GEB ~func(E) HKTB, A, E, HKTA, HKTB any](
	fchain chain.ChainType[A, HKTA, HKTB],
	f func(A) GEB,
) func(GEA) GEB

func ChainFirst added in v2.3.44

func ChainFirst[GEA ~func(E) HKTA, GEB ~func(E) HKTB, A, E, HKTA, HKTB any](
	fchain chain.ChainFirstType[A, HKTA, HKTB],
	f func(A) GEB,
) func(GEA) GEA

func FromReader

func FromReader[GA ~func(E) A, GEA ~func(E) HKTA, E, A, HKTA any](
	fof pointed.OfType[A, HKTA]) func(ma GA) GEA

func Map

func Map[GEA ~func(E) HKTA, GEB ~func(E) HKTB, E, A, B, HKTA, HKTB any](
	fmap functor.MapType[A, B, HKTA, HKTB],
	f func(A) B,
) func(GEA) GEB

func MonadAp

func MonadAp[GEA ~func(E) HKTA, GEB ~func(E) HKTB, GEFAB ~func(E) HKTFAB, E, A, HKTA, HKTB, HKTFAB any](fap func(HKTFAB, HKTA) HKTB, fab GEFAB, fa GEA) GEB

HKTFAB = HKT[func(A)B]

func MonadChain

func MonadChain[GEA ~func(E) HKTA, GEB ~func(E) HKTB, A, E, HKTA, HKTB any](
	fchain chain.MonadChainType[A, HKTA, HKTB],
	ma GEA,
	f func(A) GEB,
) GEB

func MonadChainFirst added in v2.3.44

func MonadChainFirst[GEA ~func(E) HKTA, GEB ~func(E) HKTB, A, E, HKTA, HKTB any](
	fchain chain.MonadChainFirstType[A, HKTA, HKTB],
	ma GEA,
	f func(A) GEB,
) GEA

func MonadFromReader

func MonadFromReader[GA ~func(E) A, GEA ~func(E) HKTA, E, A, HKTA any](
	fof pointed.OfType[A, HKTA], ma GA) GEA

func MonadMap

func MonadMap[GEA ~func(E) HKTA, GEB ~func(E) HKTB, E, A, B, HKTA, HKTB any](
	fmap func(HKTA, func(A) B) HKTB,
	fa GEA,
	f func(A) B,
) GEB

func MonadOf

func MonadOf[GEA ~func(E) HKTA, E, A, HKTA any](fof pointed.OfType[A, HKTA], a A) GEA

func Sequence

func Sequence[
	HKTR2HKTR1A ~func(R2) HKTR1HKTA,
	R1, R2, HKTR1HKTA, HKTA any](
	mchain func(func(func(R1) HKTA) HKTA) func(HKTR1HKTA) HKTA,
	ma HKTR2HKTR1A,
) func(R1) func(R2) HKTA

func SequenceReader

func SequenceReader[
	HKTR2HKTR1A ~func(R2) HKTR1HKTA,
	R1, R2, A, HKTR1HKTA, HKTA any](
	mmap func(func(func(R1) A) A) func(HKTR1HKTA) HKTA,
	ma HKTR2HKTR1A,
) func(R1) func(R2) HKTA

func Traverse

func Traverse[
	HKTR2A ~func(R2) HKTA,
	HKTR1B ~func(R1) HKTB,
	R1, R2, A, HKTR1HKTB, HKTA, HKTB any](
	mmap func(func(A) HKTR1B) func(HKTA) HKTR1HKTB,
	mchain func(func(func(R1) HKTB) HKTB) func(HKTR1HKTB) HKTB,
	f func(A) HKTR1B,
) func(HKTR2A) func(R1) func(R2) HKTB

func TraverseReader

func TraverseReader[
	HKTR2A ~func(R2) HKTA,
	HKTR1B ~func(R1) B,
	R1, R2, A, B, HKTR1HKTB, HKTA, HKTB any](
	mmap1 func(func(A) HKTR1B) func(HKTA) HKTR1HKTB,
	mmap2 func(func(func(R1) B) B) func(HKTR1HKTB) HKTB,
	f func(A) HKTR1B,
) func(HKTR2A) func(R1) func(R2) HKTB

Types

This section is empty.

Jump to

Keyboard shortcuts

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