gog

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 0 Imported by: 9

README

GoG (Go Generics)

GoG is a Go library with useful generic functions and types.

Documentation

Overview

Package gog provides utilities for working with Go generics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dedupe added in v0.2.0

func Dedupe[T comparable](slice []T) []T

Dedupe returns a new slice that contains only distinct elements from the original slice.

func Map

func Map[S, T any](slice []S, fn func(S) T) []T

Map can be used to transform one slice into another by providing a function to do the mapping.

func Partition

func Partition[S any, K comparable](slice []S, fn func(S) K) map[K][]S

Partition splits the specified slice into groups, each having a key according to the specified function.

func PtrOf

func PtrOf[T any](v T) *T

PtrOf returns a pointer to the passed value.

func Reduce

func Reduce[S, T any](slice []S, initialValue T, fn func(accum T, value S) T) T

Reduce compacts a slice into a single value. The provided function is used to perform the reduction starting with the initialValue.

func Select

func Select[S any](slice []S, fn func(S) bool) []S

Select returns a new slice that contains only the elements of the original slice that pass the filter function.

func ValueOf

func ValueOf[T any](v *T, defaultValue T) T

ValueOf is the opposite of PtrOf. It takes a pointer an dereferences it. If the pointer is nil, then it uses the provided defaultValue.

Types

This section is empty.

Directories

Path Synopsis
Package ds provides various data structure implementations with generics.
Package ds provides various data structure implementations with generics.
Package filter adds helper functions for performing filtering over a data set.
Package filter adds helper functions for performing filtering over a data set.
Package opt provides utilities for optional types.
Package opt provides utilities for optional types.

Jump to

Keyboard shortcuts

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