folders

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package folders defines the folders API and a library of folders implementations. These functions can be used with various Fold methods in the other packages in this library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LargestFolder

func LargestFolder[T cmp.Ordered](accumulator T, value T) result.Result[T]

LargestFolder returns the largest of a given value and an accumulator value.

func SmallestFolder

func SmallestFolder[T cmp.Ordered](accumulator T, value T) result.Result[T]

SmallestFolder returns the smallest of a given value and an accumulator value.

Types

type Folder

type Folder[T, S any] func(accumulator T, source S) result.Result[T]

Folder is a function that can transform a source value and store it in a target value. The various Fold functions will call a Folder repeatedly feeding the value in the returned result as the accumulator each call.

func NewCountingFolder

func NewCountingFolder[S any](step int) Folder[int, S]

NewCountingFolder returns a new Folder function that increments the accumulator value by the given step amount for each element folded over. The elements are ignored.

func NewMapFolder

func NewMapFolder[S any, K comparable, V any](
	toKey ToKey[S, K],
	toValue ToValue[S, V],
) Folder[map[K]V, S]

NewMapFolder returns a new Folder function that takes two functions, applies the toKey function and toValue function to the element being folded over and sets the resulting key to be the resulting value in the provided accumulator map.

func NewMatchesFolder

func NewMatchesFolder[T any](filter filters.Filter[T]) Folder[[]T, T]

NewMatchesFolder returns a new Folder function that applies a Filter function to a given value and appends it to a provided accumulator slice for a match.

func NewSliceFolder

func NewSliceFolder[S any]() Folder[[]S, S]

NewSliceFolder returns a new Folder function that appends each element folded over to the accumulator slice. This is similar to calling append(accumulator, slice...) except that this folder can be used in a call to sliceutils.Fold*.

type FolderNoError

type FolderNoError[T, S any] func(accumulator T, source S) T

FolderNoError is a function that can transform a source value and store it in a target value. The various Fold functions will call a FolderNoError repeatedly feeding the returned value as the accumulator each call.

func NewMatchesFolderNoError

func NewMatchesFolderNoError[T any](filter filters.FilterNoError[T]) FolderNoError[[]T, T]

NewMatchesFolderNoError returns a new Folder function that applies a Filter function to a given value and appends it to a provided accumulator slice for a match.

type ToKey

type ToKey[S any, K comparable] func(source S) result.Result[K]

ToKey is a function that can convert a source value to a key.

type ToValue

type ToValue[S, V any] func(value S) result.Result[V]

ToValue is a function that can convert a source value to another value.

Jump to

Keyboard shortcuts

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