fp

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 0 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](inputs []T, filter FilterFn[T]) []T

Returns an array of elements for which the filter evaluated to true

func Find

func Find[T any](inputs []T, filter FilterFn[T]) *T

Returns the first element for which the filter evaluated to true or nil if none found

func Flat

func Flat[T any](inputs [][]T) []T

Flattens nested arrays

func ForEach

func ForEach[T any](inputs []T, fn ForEachFn[T]) error

Executes fn for each element in the array

Returns early if an error is returned

func Map

func Map[Input, Output any](inputs []Input, mapper MapFn[Input, Output]) ([]Output, error)

Executes mapper for each element, returning the result

Returns early if an error is returned

func Reduce

func Reduce[Accumulator, T any](inputs []T, initializer Accumulator, reducer ReduceFn[Accumulator, T]) (*Accumulator, error)

Executes reducer for each element, the result being included in the parameter of the next execution

Returns early if an error is given

Types

type FilterFn

type FilterFn[T any] func(element T, index int) bool

type ForEachFn

type ForEachFn[T any] func(element T, index int) error

type MapFn

type MapFn[Input, Output any] func(element Input, index int) (Output, error)

type ReduceFn

type ReduceFn[Accumulator, T any] func(accumulator Accumulator, element T, index int) (Accumulator, error)

Jump to

Keyboard shortcuts

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