collections

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 4 Imported by: 5

Documentation

Overview

Copyright 2022. Motty Cohen.

We often need our programs to perform operations on collections of data, like selecting all items that satisfy a given predicate or mapping all items to a new collection with a custom function.

Copyright 2022. Motty Cohen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIfNotExists

func AddIfNotExists(vs []string, t string) []string

Add item to list only if it does not exist

func All

func All(vs []string, f func(string) bool) bool

All returns `true` if all the strings in the slice satisfy the predicate `f`.

func AllN

func AllN(vs []int, f func(int) bool) bool

AllN returns `true` if all the integers in the slice satisfy the predicate `f`.

func Any

func Any(vs []string, f func(string) bool) bool

Any returns `true` if one of the strings in the slice satisfies the predicate `f`.

func AnyN

func AnyN(vs []int, f func(int) bool) bool

AnyN returns `true` if one of the integers in the slice satisfies the predicate `f`.

func BitMaskInclude

func BitMaskInclude(src, flag int) bool

BitMaskInclude checks if the src bitmask including the flag

func Concat

func Concat(slices ...[]string) []string

Concatenate multiple string slices efficiently

func ConcatN

func ConcatN(slices ...[]int) []int

Concatenate multiple int slices efficiently

func Distinct

func Distinct(vs []string) []string

Distinct returns a new slice without duplications

func DistinctN

func DistinctN(vs []int) []int

DistinctN returns a new slice without duplications

func Filter

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing all strings in the slice that satisfy the predicate `f`.

func FilterN

func FilterN(vs []int, f func(int) bool) []int

FilterN returns a new slice containing all integers in the slice that satisfy the predicate `f`.

func Include

func Include(vs []string, t string) bool

Include returns `true` if the target string t is in the slice.

func IncludeMask

func IncludeMask(vs []int, t int) bool

func IncludeN

func IncludeN(vs []int, t int) bool

IncludeN returns `true` if the target int t is in the slice.

func Index

func Index(vs []string, t string) int

Index returns the first index of the target string `t`, or -1 if no match is found.

func IndexN

func IndexN(vs []int, t int) int

IndexN returns the first index of the target int `t`, or -1 if no match is found.

func Intersect

func Intersect(slices ...[]string) []string

Intersect returns only the string values in all slices

func IntersectN

func IntersectN(slices ...[]int) []int

Intersect returns only the values in all slices

func JoinN

func JoinN(slice []int, sep string) string

JoinN convert all integers in the slice to strings and joins them together as a single string with separator

func Map

func Map(vs []string, f func(string) string) []string

Map returns a new slice containing the results of applying the function `f` to each string in the original slice.

func MapN

func MapN(vs []int, f func(int) int) []int

MapN returns a new slice containing the results of applying the function `f` to each integers in the original slice.

func Remove

func Remove(vs []string, t string) []string

Remove an item from the array

Types

type ConcurrentStringMap

type ConcurrentStringMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewConcurrentStringMap

func NewConcurrentStringMap() ConcurrentStringMap

func (*ConcurrentStringMap) Get

func (c *ConcurrentStringMap) Get(key string) (val string)

func (*ConcurrentStringMap) Put

func (c *ConcurrentStringMap) Put(key string, val string)

type Queue

type Queue interface {
	// Push item into a queue
	Push(v any)

	// Pop last item
	Pop() (any, bool)

	// Get length of the queue
	Length() int
}

Queue functions for manager data items in a stack

func NewQueue

func NewQueue() Queue

New get queue functions manager

type Stack

type Stack interface {
	// push item into a stack
	Push(v any)

	// pop last item
	Pop() (any, bool)

	// pop many items
	PopMany(count int64) ([]any, bool)

	// pop all items
	PopAll() ([]any, bool)

	// peek last item
	Peek() (any, bool)

	// get length of stack
	Length() int64

	// is empty stack
	IsEmpty() bool
}

Stack functions for manager data items in a stack

func NewStack

func NewStack() Stack

New get stack functions manager

Jump to

Keyboard shortcuts

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