mapper

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlatMap

func FlatMap[E any, T any](from []E, fn func(fromEntry E) []T) []T

FlatMap can be used to convert any list from MemberType E to T. It takes a list of E (E can also be a *E) and a function that is used for each element of E to []T. Instead of returning [][]T, the resulting list gets flattened to []T. Mapping: [[-][-][-]] [[-][-][-]] -> [+][+][+][+][+][+]

func Map

func Map[E any, T any](from []E, fn func(fromEntry E) T) []T

Map can be used to convert any list from MemberType E to T. It takes a list of E (E can also be a *E) and a function that is used for each element of E to T. It returns a []T after all.

Mapping: [-][-][-] -> [+][+][+]

func MapWithErr

func MapWithErr[E any, T any](from []E, fn func(fromEntry E) (T, error)) ([]T, error)

MapWithErr behaves like PointerMap, but stops mapping when fn returns an error. The first error that occurs is returned.

func MergeMaps

func MergeMaps[K comparable, V any](m1 map[K]V, m2 map[K]V) map[K]V

MergeMaps merges two maps of same key and value types together. The second map m2 takes precedence in case of overlapping keys.

func Reduce

func Reduce[E any, T any](from []E, initial T, fn func(accumulator T, current E) T) T

Reduce converts any list of type E into one element of type T. The reducer function fn is called for each element of the from slice and an accumulated value of type T, starting with initial.

Types

This section is empty.

Jump to

Keyboard shortcuts

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