reader

package
v1.0.153 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ap

func Ap[B, R, A any](fa Reader[R, A]) func(Reader[R, func(A) B]) Reader[R, B]

Ap applies a function to an argument under a type constructor.

func ApS added in v1.0.107

func ApS[R, S1, S2, T any](
	setter func(T) func(S1) S2,
	fa Reader[R, T],
) func(Reader[R, S1]) Reader[R, S2]

ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently

func ApplicativeMonoid

func ApplicativeMonoid[R, A any](
	_of func(A) func(R) A,
	_map func(func(R) A, func(A) func(A) A) func(R, func(A) A),
	_ap func(func(R, func(A) A), func(R) A) func(R) A,

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

func ApplySemigroup

func ApplySemigroup[R, A any](
	_map func(func(R) A, func(A) func(A) A) func(R, func(A) A),
	_ap func(func(R, func(A) A), func(R) A) func(R) A,

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

func Bind added in v1.0.107

func Bind[R, S1, S2, T any](
	setter func(T) func(S1) S2,
	f func(S1) Reader[R, T],
) func(Reader[R, S1]) Reader[R, S2]

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

func BindTo added in v1.0.107

func BindTo[R, S1, T any](
	setter func(T) S1,
) func(Reader[R, T]) Reader[R, S1]

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

func Chain

func Chain[R, A, B any](f func(A) Reader[R, B]) func(Reader[R, A]) Reader[R, B]

Chain composes computations in sequence, using the return value of one computation to determine the next computation.

func Compose

func Compose[R, B, C any](ab Reader[R, B]) func(Reader[B, C]) Reader[R, C]

func Curry1

func Curry1[R, T1, A any](f func(R, T1) A) func(T1) Reader[R, A]

func Curry2

func Curry2[R, T1, T2, A any](f func(R, T1, T2) A) func(T1) func(T2) Reader[R, A]

func Curry3

func Curry3[R, T1, T2, T3, A any](f func(R, T1, T2, T3) A) func(T1) func(T2) func(T3) Reader[R, A]

func Curry4

func Curry4[R, T1, T2, T3, T4, A any](f func(R, T1, T2, T3, T4) A) func(T1) func(T2) func(T3) func(T4) Reader[R, A]

func Flap added in v1.0.47

func Flap[R, A, B any](a A) func(Reader[R, func(A) B]) Reader[R, B]

func From0

func From0[F ~func(C) R, C, R any](f F) func() Reader[C, R]

From0 converts a function with 1 parameters returning a [R] into a function with 0 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From1

func From1[F ~func(C, T0) R, T0, C, R any](f F) func(T0) Reader[C, R]

From1 converts a function with 2 parameters returning a [R] into a function with 1 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From10

func From10[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) R, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Reader[C, R]

From10 converts a function with 11 parameters returning a [R] into a function with 10 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From2

func From2[F ~func(C, T0, T1) R, T0, T1, C, R any](f F) func(T0, T1) Reader[C, R]

From2 converts a function with 3 parameters returning a [R] into a function with 2 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From3

func From3[F ~func(C, T0, T1, T2) R, T0, T1, T2, C, R any](f F) func(T0, T1, T2) Reader[C, R]

From3 converts a function with 4 parameters returning a [R] into a function with 3 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From4

func From4[F ~func(C, T0, T1, T2, T3) R, T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) Reader[C, R]

From4 converts a function with 5 parameters returning a [R] into a function with 4 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From5

func From5[F ~func(C, T0, T1, T2, T3, T4) R, T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) Reader[C, R]

From5 converts a function with 6 parameters returning a [R] into a function with 5 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From6

func From6[F ~func(C, T0, T1, T2, T3, T4, T5) R, T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) Reader[C, R]

From6 converts a function with 7 parameters returning a [R] into a function with 6 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From7

func From7[F ~func(C, T0, T1, T2, T3, T4, T5, T6) R, T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Reader[C, R]

From7 converts a function with 8 parameters returning a [R] into a function with 7 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From8

func From8[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) R, T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Reader[C, R]

From8 converts a function with 9 parameters returning a [R] into a function with 8 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func From9

func From9[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) R, T0, T1, T2, T3, T4, T5, T6, T7, T8, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Reader[C, R]

From9 converts a function with 10 parameters returning a [R] into a function with 9 parameters returning a [Reader[C, R]] The first parameter is considered to be the context [C] of the reader

func Let added in v1.0.107

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

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

func LetTo added in v1.0.107

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

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

func Local

func Local[R2, R1, A any](f func(R2) R1) func(Reader[R1, A]) Reader[R2, A]

Local changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s `contramap`).

func Map

func Map[E, A, B any](f func(A) B) func(Reader[E, A]) Reader[E, B]

Map can be used to turn functions `func(A)B` into functions `(fa F[A])F[B]` whose argument and return types use the type constructor `F` to represent some computational context.

func Promap

func Promap[E, A, D, B any](f func(D) E, g func(A) B) func(Reader[E, A]) Reader[D, B]

func Read

func Read[E, A any](e E) func(Reader[E, A]) A

Read applies a context to a reader to obtain its value

func TraverseArray

func TraverseArray[R, A, B any](f func(A) Reader[R, B]) func([]A) Reader[R, []B]

TraverseArray transforms an array

func TraverseArrayWithIndex added in v1.0.29

func TraverseArrayWithIndex[R, A, B any](f func(int, A) Reader[R, B]) func([]A) Reader[R, []B]

TraverseArrayWithIndex transforms an array

func Uncurry0

func Uncurry0[R, A any](f Reader[R, A]) func(R) A

func Uncurry1

func Uncurry1[R, T1, A any](f func(T1) Reader[R, A]) func(R, T1) A

func Uncurry2

func Uncurry2[R, T1, T2, A any](f func(T1) func(T2) Reader[R, A]) func(R, T1, T2) A

func Uncurry3

func Uncurry3[R, T1, T2, T3, A any](f func(T1) func(T2) func(T3) Reader[R, A]) func(R, T1, T2, T3) A

func Uncurry4

func Uncurry4[R, T1, T2, T3, T4, A any](f func(T1) func(T2) func(T3) func(T4) Reader[R, A]) func(R, T1, T2, T3, T4) A

Types

type Reader

type Reader[R, A any] func(R) A

The purpose of the `Reader` monad is to avoid threading arguments through multiple functions in order to only get them where they are needed. The first template argument `R` is the the context to read from, the second argument `A` is the return value of the monad

func Ask

func Ask[R any]() Reader[R, R]

Ask reads the current context

func Asks

func Asks[R, A any](f Reader[R, A]) Reader[R, A]

Asks projects a value from the global context in a Reader

func AsksReader

func AsksReader[R, A any](f func(R) Reader[R, A]) Reader[R, A]

func Curry0

func Curry0[R, A any](f func(R) A) Reader[R, A]

func Do added in v1.0.107

func Do[R, S any](
	empty S,
) Reader[R, S]

Bind creates an empty context of type [S] to be used with the Bind operation

func First

func First[A, B, C any](pab Reader[A, B]) Reader[T.Tuple2[A, C], T.Tuple2[B, C]]

func Flatten

func Flatten[R, A any](mma func(R) Reader[R, A]) Reader[R, A]

func MakeReader

func MakeReader[R, A any](r Reader[R, A]) Reader[R, A]

MakeReader creates a reader, i.e. a method that accepts a context and that returns a value

func MonadAp

func MonadAp[B, R, A any](fab Reader[R, func(A) B], fa Reader[R, A]) Reader[R, B]

func MonadChain

func MonadChain[R, A, B any](ma Reader[R, A], f func(A) Reader[R, B]) Reader[R, B]

func MonadFlap added in v1.0.47

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

func MonadMap

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

func Of

func Of[R, A any](a A) Reader[R, A]

func Second

func Second[A, B, C any](pbc Reader[B, C]) Reader[T.Tuple2[A, B], T.Tuple2[A, C]]

func SequenceArray

func SequenceArray[R, A any](ma []Reader[R, A]) Reader[R, []A]

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

func SequenceT1

func SequenceT1[R, A any](a Reader[R, A]) Reader[R, T.Tuple1[A]]

func SequenceT2

func SequenceT2[R, A, B any](a Reader[R, A], b Reader[R, B]) Reader[R, T.Tuple2[A, B]]

func SequenceT3

func SequenceT3[R, A, B, C any](a Reader[R, A], b Reader[R, B], c Reader[R, C]) Reader[R, T.Tuple3[A, B, C]]

func SequenceT4

func SequenceT4[R, A, B, C, D any](a Reader[R, A], b Reader[R, B], c Reader[R, C], d Reader[R, D]) Reader[R, T.Tuple4[A, B, C, D]]

Directories

Path Synopsis
Code generated by go generate; DO NOT EDIT.
Code generated by go generate; DO NOT EDIT.

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy