Documentation
¶
Index ¶
- func Append[GA ~[]A, A any](as GA, a A) GA
- func Concat[GT ~[]T, T any](left, right GT) GT
- func ConstNil[GA ~[]A, A any]() GA
- func Empty[GA ~[]A, A any]() GA
- func IsEmpty[GA ~[]A, A any](as GA) bool
- func IsNil[GA ~[]A, A any](as GA) bool
- func IsNonNil[GA ~[]A, A any](as GA) bool
- func Map[GA ~[]A, GB ~[]B, A, B any](f func(a A) B) func(GA) GB
- func MonadMap[GA ~[]A, GB ~[]B, A, B any](as GA, f func(a A) B) GB
- func MonadMapWithIndex[GA ~[]A, GB ~[]B, A, B any](as GA, f func(idx int, a A) B) GB
- func MonadSequence[GA ~[]HKTA, HKTA, HKTRA any](fof func(HKTA) HKTRA, empty HKTRA, concat func(HKTRA, HKTRA) HKTRA, ta GA) HKTRA
- func MonadSequenceSegment[HKTB, HKTRB any](fof func(HKTB) HKTRB, empty HKTRB, concat func(HKTRB, HKTRB) HKTRB, fbs []HKTB, ...) HKTRB
- func MonadTraverse[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) HKTRB
- func MonadTraverseReduce[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) HKTRB
- func MonadTraverseReduceWithIndex[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) HKTRB
- func MonadTraverseWithIndex[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) HKTRB
- func Of[GA ~[]A, A any](a A) GA
- func Prepend[ENDO ~func(AS) AS, AS ~[]A, A any](head A) ENDO
- func Push[GA ~[]A, A any](as GA, a A) GA
- func Reduce[GA ~[]A, A, B any](fa GA, f func(B, A) B, initial B) B
- func ReduceRight[GA ~[]A, A, B any](fa GA, f func(A, B) B, initial B) B
- func ReduceRightWithIndex[GA ~[]A, A, B any](fa GA, f func(int, A, B) B, initial B) B
- func ReduceWithIndex[GA ~[]A, A, B any](fa GA, f func(int, B, A) B, initial B) B
- func Reverse[GT ~[]T, T any](as GT) GT
- func Sequence[GA ~[]HKTA, HKTA, HKTRA any](fof func(HKTA) HKTRA, empty HKTRA, concat func(HKTRA, HKTRA) HKTRA) func(GA) HKTRA
- func SequenceSegment[HKTB, HKTRB any](fof func(HKTB) HKTRB, empty HKTRB, concat func(HKTRB, HKTRB) HKTRB) func([]HKTB) HKTRB
- func Slice[GA ~[]A, A any](low, high int) func(as GA) GA
- func SliceRight[GA ~[]A, A any](start int) func(as GA) GA
- func Traverse[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) func(GA) HKTRB
- func TraverseReduce[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) func(GA) HKTRB
- func TraverseReduceWithIndex[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) func(GA) HKTRB
- func TraverseWithIndex[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any](fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, ...) func(GA) HKTRB
- func UpsertAt[GA ~[]A, A any](a A) func(GA) GA
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MonadMapWithIndex ¶
func MonadSequence ¶
func MonadSequence[GA ~[]HKTA, HKTA, HKTRA any]( fof func(HKTA) HKTRA, empty HKTRA, concat func(HKTRA, HKTRA) HKTRA, ta GA) HKTRA
* We need to pass the members of the applicative explicitly, because golang does neither support higher kinded types nor template methods on structs or interfaces
HKTRB = HKT<GB> HKTB = HKT<B> HKTAB = HKT<func(A)B>
func MonadSequenceSegment ¶
func MonadSequenceSegment[HKTB, HKTRB any]( fof func(HKTB) HKTRB, empty HKTRB, concat func(HKTRB, HKTRB) HKTRB, fbs []HKTB, start, end int, ) HKTRB
MonadSequenceSegment sequences a segment of an array of effects using a divide-and-conquer approach. It recursively splits the array segment in half, sequences each half, and concatenates the results.
This function is optimized for performance by using a divide-and-conquer strategy that reduces the depth of nested function calls compared to a linear fold approach.
Type parameters:
- HKTB: The higher-kinded type containing values (e.g., Option[B], Either[E, B])
- HKTRB: The higher-kinded type containing an array of values (e.g., Option[[]B], Either[E, []B])
Parameters:
- fof: Function to lift a single HKTB into HKTRB
- empty: The empty/identity value for HKTRB
- concat: Function to concatenate two HKTRB values
- fbs: The array of effects to sequence
- start: The starting index of the segment (inclusive)
- end: The ending index of the segment (exclusive)
Returns:
- HKTRB: The sequenced result for the segment
The function handles three cases:
- Empty segment (end - start == 0): returns empty
- Single element (end - start == 1): returns fof(fbs[start])
- Multiple elements: recursively divides and conquers
func MonadTraverse ¶
func MonadTraverse[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, ta GA, f func(A) HKTB) HKTRB
MonadTraverse maps each element of an array to an effect, then sequences the results. This is the monadic version that takes the array as a direct parameter.
Traverse combines mapping and sequencing in one operation. It's useful when you want to transform each element of an array into an effect (like Option, Either, IO, etc.) and then collect all those effects into a single effect containing an array.
We need to pass the members of the applicative explicitly, because golang does neither support higher kinded types nor template methods on structs or interfaces.
Type parameters:
- GA: The input array type (e.g., []A)
- GB: The output array type (e.g., []B)
- A: The input element type
- B: The output element type
- HKTB: HKT<B> - The effect containing B (e.g., Option[B])
- HKTAB: HKT<func(B)GB> - Intermediate applicative type
- HKTRB: HKT<GB> - The effect containing the result array (e.g., Option[[]B])
Parameters:
- fof: Function to lift a value into the effect (Of/Pure)
- fmap: Function to map over the effect (Map)
- fap: Function to apply an effect of a function to an effect of a value (Ap)
- ta: The input array to traverse
- f: The function to apply to each element, producing an effect
Returns:
- HKTRB: An effect containing the array of transformed values
Example:
If any element produces None, the entire result is None. If all elements produce Some, the result is Some containing all values.
func MonadTraverseReduce ¶
func MonadTraverseReduce[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, ta GA, transform func(A) HKTB, reduce func(GB, B) GB, initial GB, ) HKTRB
func MonadTraverseWithIndex ¶
func MonadTraverseWithIndex[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, ta GA, f func(int, A) HKTB) HKTRB
MonadTraverseWithIndex is like MonadTraverse but the transformation function also receives the index. This is useful when the transformation depends on the element's position in the array.
Type parameters: Same as MonadTraverse
Parameters:
- fof: Function to lift a value into the effect (Of/Pure)
- fmap: Function to map over the effect (Map)
- fap: Function to apply an effect of a function to an effect of a value (Ap)
- ta: The input array to traverse
- f: The function to apply to each element with its index, producing an effect
Returns:
- HKTRB: An effect containing the array of transformed values
func Prepend ¶
func Prepend[ENDO ~func(AS) AS, AS ~[]A, A any](head A) ENDO
Prepend prepends a single value to an array
func ReduceRight ¶
func ReduceRight[GA ~[]A, A, B any](fa GA, f func(A, B) B, initial B) B
func ReduceRightWithIndex ¶
func ReduceWithIndex ¶
func Sequence ¶
func Sequence[GA ~[]HKTA, HKTA, HKTRA any]( fof func(HKTA) HKTRA, empty HKTRA, concat func(HKTRA, HKTRA) HKTRA, ) func(GA) HKTRA
func SequenceSegment ¶
func SequenceSegment[HKTB, HKTRB any]( fof func(HKTB) HKTRB, empty HKTRB, concat func(HKTRB, HKTRB) HKTRB, ) func([]HKTB) HKTRB
SequenceSegment creates a function that sequences a segment of an array of effects. Unlike MonadSequenceSegment, this returns a curried function that can be reused.
This function builds a computation tree at construction time, which can be more efficient when the same sequencing pattern needs to be applied multiple times to arrays of the same length.
Type parameters:
- HKTB: The higher-kinded type containing values
- HKTRB: The higher-kinded type containing an array of values
Parameters:
- fof: Function to lift a single HKTB into HKTRB
- empty: The empty/identity value for HKTRB
- concat: Function to concatenate two HKTRB values
Returns:
- A function that takes an array of HKTB and returns HKTRB
func SliceRight ¶
func Traverse ¶
func Traverse[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, f func(A) HKTB) func(GA) HKTRB
Traverse creates a curried function that maps each element to an effect and sequences the results. This is the curried version of MonadTraverse, useful for partial application and composition.
Type parameters: Same as MonadTraverse
Parameters:
- fof: Function to lift a value into the effect (Of/Pure)
- fmap: Function to map over the effect (Map)
- fap: Function to apply an effect of a function to an effect of a value (Ap)
- f: The function to apply to each element, producing an effect
Returns:
- A function that takes an array and returns an effect containing the transformed array
func TraverseReduce ¶
func TraverseReduce[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, transform func(A) HKTB, reduce func(GB, B) GB, initial GB, ) func(GA) HKTRB
func TraverseReduceWithIndex ¶
func TraverseReduceWithIndex[GA ~[]A, GB, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, transform func(int, A) HKTB, reduce func(GB, B) GB, initial GB, ) func(GA) HKTRB
TraverseReduceWithIndex creates a curried function for index-aware custom reduction during traversal. This is the curried version of MonadTraverseReduceWithIndex.
Type parameters: Same as MonadTraverseReduce
Parameters: Same as TraverseReduce, except:
- transform: Function that takes index and element, producing an effect
Returns:
- A function that takes an array and returns an effect containing the accumulated value
func TraverseWithIndex ¶
func TraverseWithIndex[GA ~[]A, GB ~[]B, A, B, HKTB, HKTAB, HKTRB any]( fof func(GB) HKTRB, fmap func(func(GB) func(B) GB) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, f func(int, A) HKTB) func(GA) HKTRB
TraverseWithIndex creates a curried function like Traverse but with index-aware transformation. This is the curried version of MonadTraverseWithIndex.
Type parameters: Same as MonadTraverse
Parameters:
- fof: Function to lift a value into the effect (Of/Pure)
- fmap: Function to map over the effect (Map)
- fap: Function to apply an effect of a function to an effect of a value (Ap)
- f: The function to apply to each element with its index, producing an effect
Returns:
- A function that takes an array and returns an effect containing the transformed array
Types ¶
This section is empty.