reduce#
A simple map/filter/reduce package (plus some goodies) mostly inspired by Rob Pike's filter package, but this time with generics and simpler implementations.
That said, you should probably still stick to loops.
Installation#
% go get -u tangled.org/luka.ljudi.org/reduce
Note: When you copy the command, make sure not to include the % prefix.
Usage#
This is the entire API:
func All[S ~[]T, T any](s S, f func(T) bool) bool
func Any[S ~[]T, T any](s S, f func(T) bool) bool
func Not[T any](f func(T) bool) func(T) bool
func Filter[S ~[]T, T any](s S, f func(T) bool) S
func FilterInPlace[S ~[]T, T any](s S, f func(T) bool) S
func Map[S ~[]T, T any, U any](s S, f func(T) U) []U
func MapInPlace[S ~[]T, T any](s S, f func(T) T) S
func Reduce[S ~[]T, T any, U any](s S, acc U, f func(U, T) U) U
Licence#
This project is provided under the terms of the MIT licence, except for some test files that include source code derived from the filter project, copyright © The Go Authors, used under a BSD-style licence.
See the LICENCE file for details.