Simple map/filter/reduce package in Golang using generics.
0

Configure Feed

Select the types of activity you want to include in your feed.

Go 78.4%
Other 21.6%
15 1 0

Clone this repository

https://tangled.org/luka.ljudi.org/reduce https://tangled.org/did:plc:tf5dqpdjsw2n4l2a3eytpkxh
git@tangled.org:luka.ljudi.org/reduce git@tangled.org:did:plc:tf5dqpdjsw2n4l2a3eytpkxh

For self-hosted knots, clone URLs may differ based on your setup.



README.md

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.