util

package
v0.0.0-...-e86b535 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package util provides various helper functions.

I know that Map/Reduce/Filter isn't idiomatic Go, but I still find them very useful!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](l []T, query T) bool

Contains checks if a slice contains a given element.

func Filter

func Filter[T any](l []T, f func(T) bool) []T

Filter iterates over a slice and returns a slice containing only the elements for which the predicate is true.

func ForEach

func ForEach[T any](l []T, f func(T))

ForEach applies a function to each element in a slice.

func Map

func Map[T any, R any](l []T, f func(T) R) []R

Map creates a new slice from the result of calling a function on each element of an input slice.

func Reduce

func Reduce[T any, R any](l []T, f func(R, T) R, acc R) R

Reduce applies an accumulator function from left to right on a slice with a given initial value.

func Remove

func Remove[T comparable](l []T, toRemove T) []T

Remove removes all instances of an element from a slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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