lazy

package
v1.0.143 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Now = G.Now[Lazy[time.Time]]()

Now returns the current timestamp

Functions

func Ap

func Ap[B, A any](ma Lazy[A]) func(Lazy[func(A) B]) Lazy[B]

func ApFirst

func ApFirst[A, B any](second Lazy[B]) func(Lazy[A]) Lazy[A]

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

func ApS added in v1.0.107

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

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

func ApSecond

func ApSecond[A, B any](second Lazy[B]) func(Lazy[A]) Lazy[B]

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

func ApplicativeMonoid

func ApplicativeMonoid[A any](m M.Monoid[A]) M.Monoid[Lazy[A]]

func ApplySemigroup

func ApplySemigroup[A any](s S.Semigroup[A]) S.Semigroup[Lazy[A]]

func Bind added in v1.0.107

func Bind[S1, S2, T any](
	setter func(T) func(S1) S2,
	f func(S1) Lazy[T],
) func(Lazy[S1]) Lazy[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[S1, T any](
	setter func(T) S1,
) func(Lazy[T]) Lazy[S1]

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

func Chain

func Chain[A, B any](f func(A) Lazy[B]) func(Lazy[A]) Lazy[B]

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

func ChainFirst

func ChainFirst[A, B any](f func(A) Lazy[B]) func(Lazy[A]) Lazy[A]

ChainFirst composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

func ChainTo

func ChainTo[A, B any](fb Lazy[B]) func(Lazy[A]) Lazy[B]

ChainTo composes computations in sequence, ignoring the return value of the first computation

func Eq

func Eq[A any](e EQ.Eq[A]) EQ.Eq[Lazy[A]]

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

func Let added in v1.0.107

func Let[S1, S2, T any](
	setter func(T) func(S1) S2,
	f func(S1) T,
) func(Lazy[S1]) Lazy[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[S1, S2, T any](
	setter func(T) func(S1) S2,
	b T,
) func(Lazy[S1]) Lazy[S2]

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

func Map

func Map[A, B any](f func(A) B) func(fa Lazy[A]) Lazy[B]

func MapTo

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

func TraverseArray

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

TraverseArray applies a function returning an [IO] to all elements in an array and the transforms this into an [IO] of that array

func TraverseArrayWithIndex added in v1.0.29

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

TraverseArrayWithIndex applies a function returning an [IO] to all elements in an array and the transforms this into an [IO] of that array

func TraverseRecord

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

TraverseRecord applies a function returning an [IO] to all elements in a record and the transforms this into an [IO] of that record

func TraverseRecordWithIndex added in v1.0.29

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

TraverseRecord applies a function returning an [IO] to all elements in a record and the transforms this into an [IO] of that record

Types

type Lazy

type Lazy[A any] func() A

Lazy represents a synchronous computation without side effects

Example (Creation)
// lazy function of a constant value
val := Of(42)
// create another function to transform this
valS := F.Pipe1(
	val,
	Map(strconv.Itoa),
)

fmt.Println(valS())
Output:

42

func Defer

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

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

func Do added in v1.0.107

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

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

func Flatten

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

func FromImpure

func FromImpure(f func()) Lazy[any]

FromImpure converts a side effect without a return value into a side effect that returns any

func FromLazy

func FromLazy[A any](a Lazy[A]) Lazy[A]

func MakeLazy

func MakeLazy[A any](f func() A) Lazy[A]

func Memoize

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

Memoize computes the value of the provided Lazy monad lazily but exactly once

func MonadAp

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

func MonadApFirst

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

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

func MonadApSecond

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

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

func MonadChain

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

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

func MonadChainFirst

func MonadChainFirst[A, B any](fa Lazy[A], f func(A) Lazy[B]) Lazy[A]

MonadChainFirst composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.

func MonadChainTo

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

MonadChainTo composes computations in sequence, ignoring the return value of the first computation

func MonadMap

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

func MonadMapTo

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

func MonadOf

func MonadOf[A any](a A) Lazy[A]

func MonadTraverseArray

func MonadTraverseArray[A, B any](tas []A, f func(A) Lazy[B]) Lazy[[]B]

func MonadTraverseRecord

func MonadTraverseRecord[K comparable, A, B any](tas map[K]A, f func(A) Lazy[B]) Lazy[map[K]B]

func Of

func Of[A any](a A) Lazy[A]

func Retrying

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

Retrying will retry the actions according to the check policy

policy - refers to the retry policy action - converts a status into an operation to be executed check - checks if the result of the action needs to be retried

func SequenceArray

func SequenceArray[A any](tas []Lazy[A]) Lazy[[]A]

SequenceArray converts an array of [IO] to an [IO] of an array

func SequenceRecord

func SequenceRecord[K comparable, A any](tas map[K]Lazy[A]) Lazy[map[K]A]

SequenceRecord converts a record of [IO] to an [IO] of a record

func SequenceT1

func SequenceT1[A any](a Lazy[A]) Lazy[T.Tuple1[A]]

func SequenceT2

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

func SequenceT3

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

func SequenceT4

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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