Documentation ¶
Index ¶
- func Collect[S ~[]Result[T], T any](s S) ([]T, error)
- func MapValToKey[K comparable, V comparable](m map[K]V) map[V]K
- func Sieve[S ~[]Result[T], T any](s S) ([]T, []error)
- func Stream[S ~[]T, T any](ch chan T, s ...S)
- func StreamReader(ch chan *StreamedChunk, r io.Reader, chunkSize int)
- func StreamingSwitch[T any](s chan T, sinkA chan T, sinkB chan T, f func(T) bool)
- func Switch[S ~[]T, T any](s S, f func(T) bool) ([]T, []T)
- type Result
- type StreamedChunk
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect takes a slice of Result[T] and returns a slice of T or the first error encountered
func MapValToKey ¶
func MapValToKey[K comparable, V comparable](m map[K]V) map[V]K
MapValToKey takes a map with keys of type K and values of type V, and returns a new map with keys and values swapped. The values in the original map should be comparable.
func Sieve ¶
Sieve takes a slice of Result[T] and returns a slice of T with the errors removed and a slice of errors if any
func Stream ¶
func Stream[S ~[]T, T any](ch chan T, s ...S)
Stream takes many slices of T and emits each element in the slices in order on the channel `ch`, closing the channel when done
func StreamReader ¶
func StreamReader(ch chan *StreamedChunk, r io.Reader, chunkSize int)
func StreamingSwitch ¶
StreamingSwitch takes a channel of T and two channels of T and a function that returns a bool, it will apply `f` to each T in `s` and will switch each T from `s` into one of two channels based on the result of `f` until `s` is closed
Types ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result is a generic type that can hold a value of type T or an error
func Map ¶
Map takes a slice of T and a function that returns a Result[T] applies `f` to `s` and returns a slice of Result[T]
func (Result[T]) ValueOr ¶
func (r Result[T]) ValueOr(def T) T
ValueOr returns the value if there is no error, otherwise returns the default value
func (Result[T]) ValueOrFunc ¶
func (r Result[T]) ValueOrFunc(f func() T) T
ValueOrFunc returns the value if there is no error, otherwise returns the result of the function `f`
func (Result[T]) ValueOrPanic ¶
func (r Result[T]) ValueOrPanic() T
ValueOrPanic returns T if there is no error, otherwise panics