slices

package
v2.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package slices provides generic higher-order functions over slices of values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter added in v2.7.0

func Filter[X any](f func(X) bool, xs []X) []X

Filter applies function "f : X => bool" to each value X of the input slice, and returns a new slice containing only each X for which f(X) is true.

If f(X) is false for every item, this function may return a nil slice.

func FlatMap

func FlatMap[X any, Y any](f func(X) []Y, xs []X) []Y

FlatMap applies function "f : X => []Y" to each value of the input slice, and returns a new slice of each output in sequence. The output sequence is "flattened" so that each slice returned by f is concatenated into a single slice.

If the input slice is a nil slice, the return value is also a nil slice. If f returns a nil slice, it is not included in the output.

For a lazy version, see the iter package.

func Map

func Map[X any, Y any](f func(X) Y, xs []X) []Y

Map applies function "f : X => Y" to each value of the input slice, and returns a new slice of each output in sequence.

If the input slice is a nil slice, the return value is also a nil slice.

For a lazy version, see the iter package.

func Reduce added in v2.7.0

func Reduce[X any](initial X, f func(X, X) X, xs []X) X

Reduce applies function f to each element of the slice (in increasing order of element index) with the previous return value from f as the first argument and the element as the second argument (for the first call to f, the supplied initial value is used instead of a return value), returning the final value returned by f.

If the input slice is empty, the result is the initial value.

func Reducer added in v2.8.0

func Reducer[X any](initial X, f func(X, X) X) func(xs []X) X

Reducer constructs a partially applied Reduce function with the arguments "initial" and "f" already bound.

Types

This section is empty.

Jump to

Keyboard shortcuts

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