goaoi

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 5 Imported by: 11

README

codecov

goaoi

img Conventional Commits

Conventient algorithms for processing iterables, inspired by the algorithm header from the C++ standard template library (STL for short). Note that *Iterator() methods return lazy iterators wrapping the underlying ones instead of changing underlying data or allocation new data.

Please do not expect a stable API at this point.

Sister project: https://github.com/JonasMuehlmann/pyaoi

Installation

go get github.com/JonasMuehlmann/goaoi

How to use

All functions live in the goaoi namespace and most have separate implementations for maps, slices, strings and https://github.com/JonasMuehlmann/datastructures.go iterators. For usage examples, refer to the test files.

API Documentation available at https://pkg.golang.ir/github.com/JonasMuehlmann/goaoi.

Predicates and functional operators

package functional provides partially specializable predicates and functional operators.

Example:

import (
	"github.com/JonasMuehlmann/goaoi"
	"github.com/JonasMuehlmann/goaoi/functional"
)


// Result: 15
sum := goaoi.AccumulateSlice([]int{1,2,3,4,5}, 0, functional.Add)
// Result: 1, nil
i, err := goaoi.FindIfSlice([]int{1,3,0,1,4,5}, 0, functional.AreEqualPartial(3))
Lazy iterator adapters

package iteratoradapters provides lazy iterator adapters for efficient iterator processing. The adapters wrap underlying ones and avoid altering, copying or allocating data. This is especially useful for chaining them on the same container like this (untested example without fully implemented API):

import (
	"github.com/JonasMuehlmann/goaoi"
	"github.com/JonasMuehlmann/goaoi/functional"
	"github.com/JonasMuehlmann/datastructures.go/lists/arraylist"
)

// NOTE: Complexities refer to space and or time

// O(1)
valuesOrig := arraylist.NewFromSlice([]int{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15})
// O(1) because lazy, would be O(N) otherwise
valid := valuesOrig.Begin().TakeWhileIterator(functional.IsLessThanEqualPartial(12))

// O(m) because lazy, would be O(N) otherwise
m := 4
parts := increased.SplitNthIterator(m)

newParts := make([]goaoi.ReadForIndexIterator[int, int], len(parts))
partsIter := parts.Beign()
for partsIter.Next() {
    // Pretend the input is larger and this actually makes sense.
    go func() {
        part, _ := partsIter.Value()
        // O(1) because lazy, would be O(N) otherwise
        newparts = append(newParts, part.TransformIterator(functional.AddPartial(5))
    }
}

// O(m) because lazy, would be O(N)
joined := goaoi.JoinIterator(newParts...)
// O(n) because the adapter's functionality need to be applied 
// for materialization of the new data.
// valuesOrig left unchanged
valuesAfterCopy := arraylist.NewFromIterator(joined)
Lazy generators

package generators provides lazy generators, which work similar to iterator adapters, but they do not reference existing data, instead they generate it themselves (lazily). Some generators have no defined end.

Example:

import (
	"github.com/JonasMuehlmann/goaoi"
	"github.com/JonasMuehlmann/goaoi/functional"
	"github.com/JonasMuehlmann/goaoi/generators"
	"github.com/JonasMuehlmann/datastructures.go/lists/arraylist"
)

// Generates 10 1s
repeater := generators.NewRepeat(1, 10)

// [1,1,1,1,1,1,1,1,1,1]
firstValues := arraylist.NewFromIterator(repeater)

// Generates infinite 1s
infiniteRepeater := generators.NewRepeat(1, -1)

// Infinite loop until OOM (Out of memory)
firstValues := arraylist.NewFromIterator(infiniteRepeater)

License

Copyright (C) 2021-2022 Jonas Muehlmann

The project is licensed under the terms of the MIT license, you can view it here.

Documentation

Overview

Package goaoi implements conventient algorithms for processing iterables. It is inspired by the algorithm header from the C++ standard template library (STL for short).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccumulateIterator added in v1.6.0

func AccumulateIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], initialAccumulator TValue, binary_func func(TValue, TValue) TValue) TValue

AccumulateIterator returns initialAccumulator after executing initialAccumulaator = binary_func(initialAccumulator, element) for each element.

func AccumulateMap added in v1.6.0

func AccumulateMap[TKey comparable, TValue comparable](container map[TKey]TValue, initialAccumulator TValue, binary_func func(TValue, TValue) TValue) TValue

AccumulateMap returns initialAccumulator after executing initialAccumulaator = binary_func(initialAccumulator, element) for each element. Note that the iteration order of a map is not stable.

func AccumulateSlice added in v1.6.0

func AccumulateSlice[T any](container []T, initialAccumulator T, binary_func func(T, T) T) T

AccumulateSlice returns initialAccumulator after executing initialAccumulaator = binary_func(initialAccumulator, element) for each element.

func AccumulateString added in v1.6.0

func AccumulateString(container string, initialAccumulator rune, binary_func func(rune, rune) rune) rune

AccumulateString returns initialAccumulator after executing initialAccumulaator = binary_func(initialAccumulator, element) for each element.

func AdjacentFindIteratorPred added in v0.7.0

func AdjacentFindIteratorPred[TKey any, TValue comparable](container ds.ReadForIndexIterator[TKey, TValue], binary_predicate func(TValue, TValue) bool) (int, error)

AdjacentFindIteratorPred finds the first index i where binary_predicate(container[i], container[i+1]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AdjacentFindSlicePred

func AdjacentFindSlicePred[T comparable](container []T, binary_predicate func(T, T) bool) (int, error)

AdjacentFindSlicePred finds the first index i where binary_predicate(container[i], container[i+1]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AdjacentFindStringPred added in v0.7.0

func AdjacentFindStringPred(container string, binary_predicate func(byte, byte) bool) (int, error)

AdjacentFindStringPred finds the first index i where binary_predicate(container[i], container[i+1]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AllOfIterator added in v0.7.0

func AllOfIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) error

AllOfIterator checks that unaryPredicate(val) == true for ALL val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func AllOfMap

func AllOfMap[TKey comparable, TValue comparable](container map[TKey]TValue, unaryPredicate func(TValue) bool) error

AllOfMap checks that unaryPredicate(val) == true for ALL val in container. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func AllOfSlice

func AllOfSlice[T any](container []T, unaryPredicate func(T) bool) error

AllOfSlice checks that unaryPredicate(val) == true for ALL val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func AllOfString added in v0.7.0

func AllOfString(container string, unaryPredicate func(rune) bool) error

AllOfString checks that unaryPredicate(val) == true for ALL val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func AnyOfIterator added in v0.7.0

func AnyOfIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) error

AnyOfIterator checks that unaryPredicate(val) == true for ANY val in container.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AnyOfMap

func AnyOfMap[TKey comparable, TValue comparable](container map[TKey]TValue, unaryPredicate func(TValue) bool) error

AnyOfMap checks that unaryPredicate(val) == true for ANY val in container. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AnyOfSlice

func AnyOfSlice[T any](container []T, unaryPredicate func(T) bool) error

AnyOfSlice checks that unaryPredicate(val) == true for ANY val in container.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func AnyOfString added in v0.7.0

func AnyOfString(container string, unaryPredicate func(rune) bool) error

AnyOfString checks that unaryPredicate(val) == true for ANY val in container.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func CountIfIterator added in v0.7.0

func CountIfIterator[TKey any, TValue comparable](container ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) (int, error)

CountIfIterator counts for how many val of container unaryPredicate(val) == true.

Possible Error values:

  • EmptyIterableError

func CountIfMap

func CountIfMap[TKey comparable, TValue comparable](container map[TKey]TValue, unaryPredicate func(TValue) bool) (int, error)

CountIfMap counts for how many val of container unaryPredicate(val) == true. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func CountIfSlice

func CountIfSlice[T comparable](container []T, unaryPredicate func(T) bool) (int, error)

CountIfSlice counts for how many val of container unaryPredicate(val) == true.

Possible Error values:

  • EmptyIterableError

func CountIfString added in v0.7.0

func CountIfString(container string, unaryPredicate func(rune) bool) (int, error)

CountIfString counts for how many val of container unaryPredicate(val) == true.

Possible Error values:

  • EmptyIterableError

func DropNIterator added in v0.7.0

func DropNIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], n int) (ds.ReadForIndexIterator[TKey, TValue], error)

DropNIterator returns a copy of original except the first n elements.

Possible Error values:

  • EmptyIterableError

func DropWhileIterator added in v0.7.0

func DropWhileIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) (ds.ReadForIndexIterator[TKey, TValue], error)

DropWhileIterator returns a copy of original until the first element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func DropWhileSlice added in v0.7.0

func DropWhileSlice[T comparable](original []T, unaryPredicate func(T) bool) ([]T, error)

DropWhileSlice returns a copy of original starting from first element not satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func DropWhileString added in v0.7.0

func DropWhileString(original string, unaryPredicate func(rune) bool) (string, error)

DropWhileString returns a copy of original starting from first element not satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func FillSlice

func FillSlice[T any](arr *[]T, filler T) []T

FillSlice fills the array pointed to by arr with filler. all indices in the range [0, cap(*arr)[ are filled regardless of what len(*arr) is.

func FindEndSlicePred

func FindEndSlicePred[T comparable](super []T, sub []T, binary_predicate func(T, T) bool) (int, error)

FindEndSlicePred finds the beginning of the last occurrence of sub in super. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindEndStringPred added in v0.7.0

func FindEndStringPred(super string, sub string, binary_predicate func(byte, byte) bool) (int, error)

FindEndStringPred finds the beginning of the last occurrence of sub in super. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindFirstOfMapPred

func FindFirstOfMapPred[TKey comparable, TValue comparable](haystack map[TKey]TValue, needles []TValue, binary_predicate func(TValue, TValue) bool) (TKey, error)

FindFirstOfMapPred finds the first key where an element of haystack is equal to any element in needles. Note that the iteration order of a map is not stable. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindFirstOfSlicePred

func FindFirstOfSlicePred[T comparable](haystack []T, needles []T, binary_predicate func(T, T) bool) (int, error)

FindFirstOfSlicePred finds the first index where an element of haystack is equal to any element in needles. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindFirstOfStringPred added in v0.7.0

func FindFirstOfStringPred(haystack string, needles string, binary_predicate func(rune, rune) bool) (int, error)

FindFirstOfStringPred finds the first index where an element of haystack is equal to any element in needles. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindIfIterator added in v0.7.0

func FindIfIterator[TKey any, TValue comparable](haystack ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) (int, error)

FindIfIterator finds the first index i where unaryPredicate(haystack[i]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindIfMap

func FindIfMap[TKey comparable, TValue comparable](haystack map[TKey]TValue, unaryPredicate func(TValue) bool) (TKey, error)

FindIfMap finds the first key where unaryPredicate(haystack[key]) == true. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindIfSlice

func FindIfSlice[T comparable](haystack []T, unaryPredicate func(T) bool) (int, error)

FindIfSlice finds the first index i where unaryPredicate(haystack[i]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func FindIfString added in v0.7.0

func FindIfString(haystack string, unaryPredicate func(rune) bool) (int, error)

FindIfString finds the first index i where unaryPredicate(haystack[i]) == true.

Possible Error values:

  • EmptyIterableError
  • ElementNotFoundError

func ForeachIterator added in v0.7.0

func ForeachIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], unary_func func(TValue) error) error

ForeachIterator executes unary_func(val) for each val in container. Errors returned by unary_func are propagated to the caller of ForeachSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func ForeachIteratorUnsafe added in v0.7.0

func ForeachIteratorUnsafe[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], unary_func func(TValue)) error

ForeachIteratorUnsafe executes unary_func(val) for each val in container. Errors returned by unary_func are propagated to the caller of ForeachSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func ForeachMap

func ForeachMap[TKey comparable, TValue comparable](container map[TKey]TValue, unary_func func(TValue) error) error

ForeachMap executes unary_func(val) for each val in container. Note that the iteration order of a map is not stable. Errors returned by unary_func are propagated to the caller of ForeachMap.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func ForeachMapUnsafe

func ForeachMapUnsafe[TKey comparable, TValue comparable](container map[TKey]TValue, unary_func func(TValue)) error

ForeachMapUnsafe executes unary_func(val) for each val in container. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func ForeachSlice

func ForeachSlice[T any](container []T, unary_func func(T) error) error

ForeachSlice executes unary_func(val) for each val in container. Errors returned by unary_func are propagated to the caller of ForeachSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func ForeachSliceUnsafe

func ForeachSliceUnsafe[T any](container []T, unary_func func(T)) error

ForeachSliceUnsafe executes unary_func(val) for each val in container.

Possible Error values:

  • EmptyIterableError

func ForeachString added in v0.7.0

func ForeachString(container string, unary_func func(rune) error) error

ForeachString executes unary_func(val) for each val in container. Errors returned by unary_func are propagated to the caller of ForeachSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func ForeachStringUnsafe added in v0.7.0

func ForeachStringUnsafe(container string, unary_func func(rune)) error

ForeachStringUnsafe executes unary_func(val) for each val in container. Errors returned by unary_func are propagated to the caller of ForeachSlice.

Possible Error values:

  • EmptyIterableError

func JoinIterator added in v0.7.0

func JoinIterator[TKey any, TValue any](originals ...ds.ReadForIndexIterator[TKey, TValue]) (ds.ReadForIndexIterator[TKey, TValue], error)

JoinIterator returns a copy of original including every element of every iterator.

Possible Error values:

  • EmptyIterableError

func MaxMapPred added in v0.1.1

func MaxMapPred[TKey comparable, TValue constraints.Ordered](haystack map[TKey]TValue, binary_predicate func(TValue, TValue) bool) (TKey, TValue, error)

MaxMapPred finds the largest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MaxSlicePred added in v0.1.1

func MaxSlicePred[T constraints.Ordered](haystack []T, binary_predicate func(T, T) bool) (int, T, error)

MaxSlicePred finds the largest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MaxStringPred added in v0.7.0

func MaxStringPred[T constraints.Ordered](haystack string, binary_predicate func(rune, rune) bool) (int, rune, error)

MaxStringPred finds the highest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinMapPred added in v0.1.1

func MinMapPred[TKey comparable, TValue constraints.Ordered](haystack map[TKey]TValue, binary_predicate func(TValue, TValue) bool) (TKey, TValue, error)

MinMapPred finds the smallest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinMaxMapPred added in v0.1.1

func MinMaxMapPred[TKey comparable, TValue constraints.Ordered](haystack map[TKey]TValue, binary_predicate_min func(TValue, TValue) bool, binary_predicate_max func(TValue, TValue) bool) (TKey, TKey, TValue, TValue, error)

MinMaxMapPred finds the smallest and largest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinMaxSlicePred added in v0.1.1

func MinMaxSlicePred[T constraints.Ordered](haystack []T, binary_predicate_min func(T, T) bool, binary_predicate_max func(T, T) bool) (int, int, T, T, error)

MinMaxSlicePred finds the smallest and largest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinMaxStringPred added in v0.7.0

func MinMaxStringPred[T constraints.Ordered](haystack []T, binary_predicate_min func(T, T) bool, binary_predicate_max func(T, T) bool) (int, int, T, T, error)

MinMaxStringPred finds the smallest and largest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinSlicePred added in v0.1.1

func MinSlicePred[T constraints.Ordered](haystack []T, binary_predicate func(T, T) bool) (int, T, error)

MinSlicePred finds the smallest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MinStringPred added in v0.7.0

func MinStringPred[T constraints.Ordered](haystack string, binary_predicate func(rune, rune) bool) (int, rune, error)

MinStringPred finds the smallest value in haystack. The elements are compared with binary_predicate.

Possible Error values:

  • EmptyIterableError

func MismatchSlicePred

func MismatchSlicePred[T comparable](iterable1 []T, iterable2 []T, binary_predicate func(T, T) bool) (int, error)

MismatchSlicePred finds the first index i where binary_predicate(iterable1[i], iterable2[i] == false).

Possible Error values:

  • EmptyIterableError
  • EqualIteratorsError

func MismatchStringPred added in v0.7.0

func MismatchStringPred(iterable1 string, iterable2 string, binary_predicate func(byte, byte) bool) (int, error)

MismatchStringPred finds the first index i where binary_predicate(iterable1[i], iterable2[i] == false).

Possible Error values:

  • EmptyIterableError
  • EqualIteratorsError

func NoneOfIterator added in v0.7.0

func NoneOfIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) error

NoneOfIterator checks that unaryPredicate(val) == true for ALL val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func NoneOfMap

func NoneOfMap[TKey comparable, TValue comparable](container map[TKey]TValue, unaryPredicate func(TValue) bool) error

NoneOfMap checks that unaryPredicate(val) == true for NO val in container. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func NoneOfSlice

func NoneOfSlice[T any](container []T, unaryPredicate func(T) bool) error

NoneOfSlice checks that unaryPredicate(val) == true for NO val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func NoneOfString added in v0.7.0

func NoneOfString(container string, unaryPredicate func(rune) bool) error

NoneOfString checks that unaryPredicate(val) == true for NO val in container.

Possible Error values:

  • EmptyIterableError
  • ComparisonError

func ReplaceIfIterator added in v0.7.0

func ReplaceIfIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool, replacement TValue) (ds.ReadForIndexIterator[TKey, TValue], error)

ReplaceIfIterator returns a copy of original with all element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func ReplaceIfMap added in v0.7.0

func ReplaceIfMap[TKey comparable, TValue comparable](original map[TKey]TValue, unaryPredicate func(TValue) bool, replacement TValue) (map[TKey]TValue, error)

ReplaceIfMap returns a copy of original where each value of a key-value pair satisfying unaryPredicate(value) == true is replaced with replacement. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func ReplaceIfSlice added in v0.7.0

func ReplaceIfSlice[T comparable](original []T, unaryPredicate func(T) bool, replacement T) ([]T, error)

ReplaceIfSlice returns a copy of original where each element satisfying unaryPredicate(element) == true is replaced with replacement.

Possible Error values:

  • EmptyIterableError

func ReplaceIfString added in v0.7.0

func ReplaceIfString(original string, unaryPredicate func(rune) bool, replacement rune) (string, error)

ReplaceIfString returns a copy of original with all element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func StridedIterator added in v0.7.0

func StridedIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], n int) (ds.ReadForIndexIterator[TKey, TValue], error)

StridedIterator returns a copy of original including every nth element.

Possible Error values:

  • EmptyIterableError

func TakeIfIterator added in v0.7.0

func TakeIfIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) (ds.ReadForIndexIterator[TKey, TValue], error)

TakeIfString returns a copy of original with all element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TakeIfMap added in v0.7.0

func TakeIfMap[TKey comparable, TValue comparable](original map[TKey]TValue, unaryPredicate func(TValue) bool) (map[TKey]TValue, error)

TakeIfMap returns a copy of original with all key-value pairs satisfying unaryPredicate(value) == true). Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func TakeIfSlice added in v0.7.0

func TakeIfSlice[T comparable](original []T, unaryPredicate func(T) bool) ([]T, error)

TakeIfSlice returns a copy of original with all element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TakeIfString added in v0.7.0

func TakeIfString(original string, unaryPredicate func(rune) bool) (string, error)

TakeIfString returns a copy of original with all element satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TakeNIterator added in v0.7.0

func TakeNIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], n int) (ds.ReadForIndexIterator[TKey, TValue], error)

TakeNIterator returns a copy of original including up to the first n elements.

Possible Error values:

  • EmptyIterableError

func TakeWhileIterator added in v0.7.0

func TakeWhileIterator[TKey any, TValue any](original ds.ReadForIndexIterator[TKey, TValue], unaryPredicate func(TValue) bool) (ds.ReadForIndexIterator[TKey, TValue], error)

TakeWhileIterator returns a copy of original until the first element not satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TakeWhileSlice added in v0.7.0

func TakeWhileSlice[T comparable](original []T, unaryPredicate func(T) bool) ([]T, error)

TakeWhileSlice returns a copy of original until the first element not satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TakeWhileString added in v0.7.0

func TakeWhileString(original string, unaryPredicate func(rune) bool) (string, error)

TakeWhileString returns a copy of original until the first element not satisfying unaryPredicate(element) == true).

Possible Error values:

  • EmptyIterableError

func TransformCopyMap added in v0.7.0

func TransformCopyMap[TKey comparable, TValue comparable, TValueOut any](container map[TKey]TValue, transformer func(TValue) (TValueOut, error)) (map[TKey]TValueOut, error)

TransformCopyMap applies transformer(value) for all key-value pairs in container and and returns the newly created container. Note that the iteration order of a map is not stable. Note that the transformer can return a different type than it's input. Errors returned by transformer are propagated to the caller of TransformCopyMap.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformCopyMapUnsafe added in v0.7.0

func TransformCopyMapUnsafe[TKey comparable, TValue comparable, TValueOut any](container map[TKey]TValue, transformer func(TValue) TValueOut) (map[TKey]TValueOut, error)

TransformCopyMapUnsafe applies transformer(value) for all key-value pairs in container and and returns the newly created container. Note that the transformer can return a different type than it's input. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func TransformCopySlice added in v0.7.0

func TransformCopySlice[T any, TOut any](container []T, transformer func(T) (TOut, error)) ([]TOut, error)

TransformCopySlice applies transformer(container[i]) for all i in [0, len(container)[ and and returns the newly created container. Note that the transformer can return a different type than it's input. Errors returned by transformer are propagated to the caller of TransformCopySlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformCopySliceUnsafe added in v0.7.0

func TransformCopySliceUnsafe[T any, TOut any](container []T, transformer func(T) TOut) ([]TOut, error)

TransformCopySliceUnsafe applies transformer(container[i]) for all i in [0, len(container)[ and and returns the newly created container. Note that the transformer can return a different type than it's input.

Possible Error values:

  • EmptyIterableError

func TransformCopyString added in v0.7.0

func TransformCopyString(container string, transformer func(rune) (rune, error)) (string, error)

TransformCopySlice applies transformer(container[i]) for all i in [0, len(container)[ and and returns the newly created container. Note that the transformer can return a different type than it's input. Errors returned by transformer are propagated to the caller of TransformCopySlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformCopyStringUnsafe added in v0.7.0

func TransformCopyStringUnsafe(container string, transformer func(rune) rune) (string, error)

TransformCopySlice applies transformer(container[i]) for all i in [0, len(container)[ and and returns the newly created container. Note that the transformer can return a different type than it's input. Errors returned by transformer are propagated to the caller of TransformCopySlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformIterator added in v0.7.0

func TransformIterator[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], transformer func(TValue) (TValue, error)) (ds.ReadForIndexIterator[TKey, TValue], error)

TransformIterator applies transformer(&container[i]) for all i in [0, len(container)[ and stores them at container[i]. Errors returned by transformer are propagated to the caller of TransformSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformIteratorUnsafe added in v0.7.0

func TransformIteratorUnsafe[TKey any, TValue any](container ds.ReadForIndexIterator[TKey, TValue], transformer func(TValue) TValue) (ds.ReadForIndexIterator[TKey, TValue], error)

TransformIteratorUnsafe applies transformer(&container[i]) for all i in [0, len(container)[ and stores them at container[i]. Errors returned by transformer are propagated to the caller of TransformSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformMap

func TransformMap[TKey comparable, TValue comparable](container map[TKey]TValue, transformer func(TValue) (TValue, error)) error

TransformMap applies transformer(value) for all key-value pairs in container and stores them at container[key]. Note that the iteration order of a map is not stable. Errors returned by transformer are propagated to the caller of TransformMap.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformMapUnsafe

func TransformMapUnsafe[TKey comparable, TValue comparable](container map[TKey]TValue, transformer func(TValue) TValue) error

TransformMapUnsafe applies transformer(value) for all key-value pairs in container and stores them at container[key]. Note that the iteration order of a map is not stable.

Possible Error values:

  • EmptyIterableError

func TransformSlice

func TransformSlice[T any](container []T, transformer func(*T) error) error

TransformSlice applies transformer(&container[i]) for all i in [0, len(container)[ and stores them at container[i]. Errors returned by transformer are propagated to the caller of TransformSlice.

Possible Error values:

  • EmptyIterableError
  • ExecutionError

func TransformSliceUnsafe

func TransformSliceUnsafe[T any](container []T, transformer func(*T)) error

TransformSliceUnsafe applies transformer(&container[i]) for all i in [0, len(container)[ and stores them at container[i].

Possible Error values:

  • EmptyIterableError

Types

type ComparisonError

type ComparisonError[TIndex comparable, TItem any] struct {
	BadItemIndex TIndex
	BadItem      TItem
}

func (ComparisonError[TIndex, TItem]) Error

func (error ComparisonError[TIndex, TItem]) Error() string

type ElementNotFoundError

type ElementNotFoundError struct{}

func (ElementNotFoundError) Error

func (error ElementNotFoundError) Error() string

type EmptyIterableError

type EmptyIterableError struct{}

func (EmptyIterableError) Error

func (error EmptyIterableError) Error() string

type EqualIteratorsError

type EqualIteratorsError struct{}

func (EqualIteratorsError) Error

func (error EqualIteratorsError) Error() string

type ExecutionError

type ExecutionError[TIndex, TItem any] struct {
	BadItemIndex TIndex
	BadItem      TItem
	Inner        error
}

func (ExecutionError[TIndex, TItem]) Error

func (error ExecutionError[TIndex, TItem]) Error() string

Jump to

Keyboard shortcuts

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