slice

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 7 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 Copy

func Copy[T any](elements []T) []T

Copy makes the new slice with copied elements.

func Delete

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

Delete removes an element by index from a slice

func For

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

For applies a walker to elements of an slice. To stop walking just return the ErrBreak.

func ForEach

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

ForEach applies walker to elements without error checking.

func ForEachRef

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

ForEachRef applies walker to references without error checking

func Get

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

Get returns the element by its index in elements, 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](elements []T, by c.Converter[T, K]) map[K][]T

Group converts elements into the map containing slices of the elements separated by keys, which are retrieved using a Converter object.

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 the sclie 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](elements []T) []T

Reverse inverts slice elements

func Sort

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

Sort sorts a slice and returns the one.

func SortByOrdered

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

SortByOrdered sorts elements by a converter that thransforms a element to an Ordered (int, string and so on).

func SortCopy

func SortCopy[T any](elements []T, less func(e1, e2 T) bool) []T

SortCopy sorts copied slices

func ToString

func ToString[T any](elements []T) string

ToString converts elements to their default string representation

func ToStringRefs

func ToStringRefs[T any](references []*T) string

ToStringRefs converts references to the default string representation

func ToStringRefsf

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

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

func ToStringf

func ToStringf[T any](elements []T, 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](elements []T, 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](elements []T, 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