slice

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 8 Imported by: 6

Documentation

Overview

Package slice provides generic functions for slice types

Index

Constants

This section is empty.

Variables

View Source
var ErrBreak = it.ErrBreak

ErrBreak is the 'break' statement of the For, Track methods

Functions

func Clone added in v0.0.2

func Clone[T any, TS ~[]T](elements TS) []T

Clone makes new slice instance with copied elements.

func Delete

func Delete[T any, TS ~[]T](index int, elements TS) []T

Delete removes an element by index from the slice

func Filter added in v0.0.2

func Filter[T any, TS ~[]T](elements TS, filter c.Predicate[T]) []T

Filter creates a slice containing only the filtered elements

func Flatt added in v0.0.2

func Flatt[From, To any, FS ~[]From](elements FS, by c.Flatter[From, To]) []To

Flatt unfolds the n-dimensional slice into a n-1 dimensional slice

func For

func For[T any, TS ~[]T](elements TS, walker func(T) error) error

For applies walker to elements. To stop walking just return the ErrBreak.

func ForEach

func ForEach[T any, TS ~[]T](elements TS, walker func(T))

ForEach applies walker to elements without error checking.

func ForEachRef

func ForEachRef[T any, TS ~[]*T](references TS, walker func(T))

ForEachRef applies walker to references without error checking

func Get

func Get[T any, TS ~[]T](elements TS, index int) (T, bool)

Get returns an element from elements by index, otherwise, if the provided index is ouf of the elements, returns zero T and false in the second result

func Group

func Group[T any, K comparable, TS ~[]T](elements TS, by c.Converter[T, K]) map[K][]T

Group converts the slice into a map with keys computeable by a Converter.

func Of

func Of[T any](elements ...T) []T

Of is generic sclie constructor

func Range

func Range[T constraints.Integer](from T, to T) []T

Range generates a sclice of integers in the range defined by from and to inclusive.

func Reduce

func Reduce[T any, TS ~[]T](elements TS, by op.Binary[T]) T

Reduce reduces elements to an one.

func Reverse

func Reverse[T any, TS ~[]T](elements TS) []T

Reverse inverts elements order

func Sort

func Sort[T any, TS ~[]T](elements TS, less func(e1, e2 T) bool) []T

Sort sorts elements in place by applying the less function

func SortByOrdered

func SortByOrdered[T any, o constraints.Ordered, TS ~[]T](elements TS, by c.Converter[T, o]) []T

SortByOrdered sorts elements in place by converting them to Ordered values and applying the operator <

func ToString

func ToString[T any, TS ~[]T](elements TS) string

ToString converts elements to their default string representation

func ToStringRefs

func ToStringRefs[T any, TS ~[]*T](references TS) string

ToStringRefs converts references to the default string representation

func ToStringRefsf

func ToStringRefsf[T any, TS ~[]*T](references TS, elementFormat, nilValue, delimeter string) string

ToStringRefsf converts references to a string representation defined by a delimiter and a nil value representation

func ToStringf

func ToStringf[T any, TS ~[]T](elements TS, elementFormat, delimeter string) string

ToStringf converts elements to a string representation defined by a custom element format and a delimiter

func Track

func Track[T any, TS ~[]T](elements TS, tracker func(int, T) error) error

Track applies tracker to elements with error checking. To stop traking just return the ErrBreak.

func TrackEach

func TrackEach[T any, TS ~[]T](elements TS, tracker func(int, T))

TrackEach applies tracker to elements without error checking.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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