core

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 1 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[CollectionItem any](items []CollectionItem, filterFunc func(item CollectionItem, index int) bool) []CollectionItem

Filter deals with filtering a slice of items down to all those items that meet the predicate of the filter function.

func Find

func Find[CollectionItem any](items []CollectionItem, findFunc func(item CollectionItem, index int) bool) CollectionItem

Find deals with finding the first occurence of an item in a given slice of items. For complex data types CollectionItem should be a pointer.

func FindIndex

func FindIndex[CollectionItem any](items []CollectionItem, findFunc func(item CollectionItem, index int) bool) int

FindIndex deals with finding the index of the first occurence of an item in a given slice of items. Returns -1 when item can not be found.

func Map

func Map[Input any, Output any](inputs []Input, mapFunc func(input Input, index int) Output) []Output

Map deals with mapping a slice of Inputs to a slice of Outputs with the given mapping function.

func MapToSlice

func MapToSlice[Value any](inputMap map[string]Value) []Value

MapToSlice converts a map to a slice of values. Order is not guaranteed so do not use this where the order of items in the slice matters.

func RemoveDuplicates

func RemoveDuplicates[Value comparable](input []Value) []Value

RemoveDuplicates deals with removing duplicating values in the given slice. This only supports value types that fulfil the built-in comparable interface.

func Reverse

func Reverse[Value any](items []Value) []Value

Reverse deals with producing a copy of a given slice with items in the reverse order. This does not mutate the input slice!

func ShallowCopyMap

func ShallowCopyMap[Key comparable, Value any](inputMap map[Key]Value) map[Key]Value

ShallowCopyMap deals with making a copy of a map, shallow copying the values into the new map.

func SliceContains

func SliceContains[Value Comparable[Value]](input []Value, searchFor Value) bool

SliceContains determines whether the provided slice contains the given searchFor value.

func SliceContainsComparable

func SliceContainsComparable[Value comparable](input []Value, searchFor Value) bool

SliceContainsComparable determines whether the provided slice contains the given searchFor value where the value fulfils the built-in comparable interface, complex structs will not fulfil this interface and therefore you should implement the Equal() interface and use SliceContains.

func SliceToMapKeys

func SliceToMapKeys[Value any](inputKeys []string) map[string][]Value

SliceToMapKeys converts a slice of strings to a map where each item in the slice is a key in the map for an empty slice of values. This only works where the values in a map are slices!

func SlicesEqual

func SlicesEqual[Value comparable](a []Value, b []Value) bool

SlicesEqual determines whether to slices of the same comparable type are equal in value.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
}

Clock is an interface that provides the current time.

type Comparable

type Comparable[Value any] interface {
	Equal(value Value) bool
}

Comparable provides a custom interface for more complex equality checks between two values of the same type.

type SystemClock

type SystemClock struct{}

SystemClock is a Clock that returns the current time derived from the host system.

func (SystemClock) Now

func (d SystemClock) Now() time.Time

Jump to

Keyboard shortcuts

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