ranges

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 1 Imported by: 0

README

ranges

Go CI

ranges implements the nearest implementation of D range-based algorithms in Go, for fun and to experiment with what is possible in Go 1.18 and above.

Ranges are a concept popular in D and C++ for creating a language by which generic algorithms can be define which operate on potentially any type of container or sequence of data. Instead of redundantly defining the same algorithms over and over again for different types, you instead define how to create a range that lazily evaluates a given container or sequence in potentially many directions, and existing generic algorithms can be applied to the range.

Primitives

The library defines the following ranges primitives, as Go interfaces.

  • OutputRange[T any] - Any type you can write the following operations:
    • Put(element T) error Write to the output range.
  • InputRange[T any] - Anything iterable, with the following operations:
    • Empty() bool - Check if a range is empty.
    • Front() T - Get the current element. May panic if an empty range.
    • PopFront() - Remove the front element. May panic if an empty range.
  • ForwardRange[T any] - An InputRange[T] with additional operations:
    • Save() ForwardRange[T] - Copy the range and its position.
  • BidirectionalRange[T any] - ForwardRange[T] with additional operations:
    • Back() T - Get the current end element. May panic if an empty range.
    • PopBack() T - Remove the back/end element. May panic if an empty range.
    • SaveB() BidirectionalRange[T] - Save the position in both directions.
  • RandomAccessRange[T any] - A BidirectionalRange[T] with additional operations:
    • Get(index int) T Return an element of the range. May panic if out of bounds.
    • Len() int - Return the length of the range.
    • SaveR() RandomAccessRange[T] - Save the position with random access.

Due to limitations in Go versions below 1.21, the following convenience functions are available to convert sub types of range to their base types. These convenience functions are not necessary in Go 1.21, as the language was updated to offer better inference of compatible interface types.

  • I - Returns ForwardRange[T] as InputRange[T].
  • F - Returns BidirectionalRange[T] as ForwardRange[T].
  • B - Returns RandomAccessRange[T] as BidirectionalRange[T].

The ranges library defines the following types, which may be used as constraints for generic functions.

  • Signed - Any signed integer primitive type.
  • Unsigned - Any signed integer primitive type.
  • Integer - Any integer primitive type.
  • Float - Any floating point primitive type.
  • RealNumber - Any integer or floating point primitive type.
  • Ordered - Any primitive type that be ordered.
Tuple Types

To express tuples in Go, there are different types declared for different numbers of items. This library has the following:

  • Pair - Holds 2 values of any mix of types.
  • Triplet - Holds 3 values of any mix of types.
  • Quartet - Holds 4 values of any mix of types.
  • Quintet - Holds 5 values of any mix of types.
  • Sextet - Holds 6 values of any mix of types.
  • Septet - Holds 7 values of any mix of types.
  • Octet - Holds 8 values of any mix of types.
  • Ennead - Holds 9 values of any mix of types.
  • Decade - Holds 10 values of any mix of types.

For convenience, every tuple has a Make function for creating them, and a Get() function for returning the values as a Go native tuple, so tuples can be and split into multiple values without redundantly naming types.

// Inferred as Pair[int, string]
pair := MakePair(1, "hello")
// Split into int and string values.
num, str := pair.Get()

Error Handling

Ranges other than OutputRange do not include error values as part of their types. Algorithms in this library do not result in runtime errors. They may only panic when input to the functions producing the ranges is invalid, or when attempting to access elements that do not exist. When you wish to place values that result in errors, make the errors an explicit part of the type of your range such as InputRange[Pair[T, error]].

Remember that in Go you can forward Go's native return tuples as arguments and return values, and this integrates well with the ranges library tuple types. This can make forwarding errors easier.

func OtherFunc() int, error { /* ... */ }

func ReturnsValueAndError() int, error {
  // Create Pair[int, error]
  // Go can spread the multiple return into the arguments for us.
  pair := MakePair(OtherFunc())

  // Return both values.
  return pair.Get()
}

Lazy Evaluation

All ranges are lazily-evaluated and compute values anew on demand. This means each call to Front() or Back() on a range will return a new value of T.

Modifications to the returned objects may not be reflected in a container, such as returning a copy of a struct instead of a pointer to it. When modification to elements of an underlying container is necessary, you should create a range of pointers, as in *T. This will permit modification of underlying values.

Because values are computed on the fly, a call to a callback function may be executed each time Front() or Back() are called for ranges. You may wish to cache the results of computation in a chain of ranges by calling one the Cache functions, including Cache, CacheF, CacheB, and CacheR.

Algorithms

Nearly all algorithms accepting or producing InputRange can accept or produce a ForwardRange instead by calling a variation of the function with an F suffix. Most algorithms that can accept or produce a ForwardRange can accept or produce a BidirectionalRange with a B suffix. Some functions such as Map can be called with shortcuts for slices with an S suffix.

  • operators
    • Lt - Implements a < b for all orderable types.
    • Le - Implements a <= b for all orderable types.
    • Eq - Implements a == b for all comparable types.
    • Ne - Implements a != b for all comparable types.
    • Ge - Implements a >= b for all orderable types.
    • Gt - Implements a > b for all orderable types.
  • functional
    • Compose* - Composes several functions in a sequence, such that Compose*(f1, ..., fn)(x) produces f1(...(fn(x)))
    • Pipe* - Pipes several functions in a sequence, such that Pipe*(f1, ..., fn)(x) produces fn(...(f1(x)))
  • ranges
    • Chain - Produces an InputRange iterating over a slice of ranges.
    • Chunks - Takes InputRange chunks of a given size from an InputRange.
    • Cycle - Repeats a ForwardRange infinitely.
    • Drop - Drops up to a number of elements from the start of a range.
    • Enumerate - Yields elements with indexes (Pair[int, T]) from 0.
    • EnumerateN - Enumerate with a provided start index.
    • Flatten - Produces an InputRange from a range of ranges.
    • FlattenSB - A special variation to flatten a slice of BidirectionalRanges into a `BidirectionalRange.
    • FlattenSS - A special variation to flatten a slice of slices into a `BidirectionalRange.
    • FrontTransversal - Produces an InputRange iterating over the first value of every non-empty range in a range of ranges.
    • Generate - Creates an infinite BidirectionalRange by calling a function repeatedly.
    • Iota - A BidirectionalRange producing values from 0 value up to and excluding an end value, incrementing by 1.
    • IotaStart - Iota with a given start value to use in place of 0.
    • IotaStep - IotaStart with a step value to use in place of 1.
    • Null - Returns a BidirectionalRange that is always empty and consumes zero memory.
    • Only - Returns a BidirectionalRange through the arguments provided.
    • PadRight - Produces an InputRange with up to count items by padding the range with a given value.
    • Repeat - Creates an infinite BidirectionalRange repeating a value.
    • Retro - Returns a reversed BidirectionalRange.
    • RoundRobin - Produces an InputRange iterating over the first value of every non-empty range in a range of ranges in a cycle until all ranges are exhausted.
    • Slide - Produces a ForwardRange of chunks of a given windowSize stepping forward 1 element at a time.
    • SlideStep - Slide with a stepSize for stepping over elements.
    • Stride - Produces every step element in an InputRange.
    • Take - Takes up to a number of elements from a range.
    • Tee - Produces an InputRange that produces elements from a given range and outputs values to a given OutputRange when elements are popped.
    • ZipN - Produce a range stepping over N ranges in parallel. There are several Zip functions for different numbers of arguments.
  • output
    • AssignSink - Creates an OutputRange that assigns values to a given InputRange of pointers by dereferencing the pointers.
    • NullSink - Creates an OutputRange that discards all data.
    • SliceSink - Creates an OutputRange that appends to the given slice.
  • slices
    • Bytes - Produces BidirectionalRange[byte] from a string like []byte(s)
    • Runes - Produces BidirectionalRange[rune] from a string like []rune(s)
    • SliceRange - Produces BidirectionalRange[T] from []T
    • SliceRetro - Produces BidirectionalRange[T] from []T in reverse.
    • SlicePtrRange - Produces a BidirectionalRange[*T] from []T
    • SlicePtrRetro - Produces a BidirectionalRange[*T] from []T in reverse.
    • Slice - Produces []T from InputRange[T]
    • String - Produces string from InputRange[rune]
  • comparison
    • Among - Returns true if a value is equal to any of the values according to an eq callback.
    • AmongEq - Returns true if a value is equal to any of the values using a simple == comparison.
    • Cmp - Steps through two ranges comparing values with a cmp function and returns the result if it's nonzero. Returns -1 or 1 if ranges are different lengths.
    • CmpFunc - Produces a comparison function for all types that support < and >.
    • Equal - Returns true if two ranges are equal according to a comparison defined in a callback.
    • EqualComparable - Returns true if two ranges are equal, element by element, for all comparable types.
    • IsPermutation - Returns true if two ranges are permutations of each other in O(m + n) time by allocating a temporary map.
    • IsPermutationNoAlloc - Returns true if two ranges are permutations of each other in O(m * n) without allocating a map.
    • IsSameLength - Checks if two ranges are the same length in O(n) time.
    • Max - Returns the maximum value among all values given as arguments.
    • Min - Returns the minimum value among all values given as arguments.
    • Mismatch - Eagerly advances all ranges until the first element is found where any two elements are not equal according to a callback.
  • iteration
    • Cache - Caches results in an InputRange so Front() will be called only once per element on the original range.
    • CacheF - Caches results so Front() will only be called once per element on the original range, unless the range is saved and traversed over multiple times.
    • CacheB OR CacheR - Caching of BidirectionalRange and RandomAccessRange elements.
    • ChunkBy - Returns an InputRange that splits a range into sub-ranges when cb(a, b) returns false.
    • ChunkByValue Returns an InputRange that splits a range into sub-ranges where cb(a) == c(b).
    • Each - Calls a callback with each value of a range.
    • Exhaust - Steps through every element of a range until it's empty. Similar to Each with an empty callback function, only Front() will never be called for the range.
    • Filter - Filter any InputRange with a callback.
    • FilterB - Filter a BidirectionalRange, producing a range that can be advanced in both directions. Less efficient for moving forwards, as it requires priming the range in both directions.
    • Group - Yields pairs of (value, size) counting how many values are equal in each group according to cb(a, b).
    • GroupComparable - Group where a == b for any comparable value.
    • Joiner - Joins ranges with a separator ForwardRange between ranges.
    • JoinerSS - A special variation to join a slice of slices into a ForwardRange.
    • JoinStrings - A convenience function for creating a string from a ForwardRange of string values with a separator string.
    • Map - Map elements in any InputRange with a callback. The result of calling the callback is not stored, so use Cache when generating ranges with Map.
    • Permutations - Given a slice of values, produce a ForwardRange of all permutations of the given slice.
    • ReduceNoSeed - Eagerly reduces a range to a single value without a seed value. Panics when a range is empty.
    • SplitWhen - Splits a range where cb(a, b) == true for adjacent elements.
    • Splitter - Splits forward ranges with a separator ForwardRange between ranges where cb(a, b) == true
    • SplitterSS - A special variation to split a slice with a slice.
    • SplitterComparable - Splitter where a == b.
    • SplitString - A convenience function for splitting a string with a `string.
    • Uniq - Yields unique adjacent elements where cb(a, b) == true.
    • UniqComparable - Uniq where a == b.
  • mutation
    • Copy - Copies all values from an InputRange into an OutputRange.
    • Fill - Assigns a value to all locations in a range of pointers.
    • FillPattern - Assigns a pattern of values from a ForwardRange to all locations in a range of pointers.
    • StripLeft - Removes elements where cb(a) == true from the front of a range.
    • StripLeftComparable - StripLeft where a == value, given a provided value.
    • StripRight - Removes elements where cb(a) == true from the back of a range.
    • StripRightComparable - Removes elements where a == value from the back of a range.
    • Strip - Removes elements where cb(a) == true from the front and back of a range.
    • StripComparable - Removes elements where a == value from the front and back of a range.
  • searching
    • All - Checks if all elements in an InputRange satisfy a callback.
    • Any - Checks if any elements in an InputRange satisfy a callback.
    • CanFind - Find, but simply returns true if anything can be found.
    • CanFindComparable - FindComparable but simply returns true if anything can be found.
    • Length - Returns the number of elements in an InputRange in O(n) time.
    • Count - Returns the number of elements in an InputRange where the callback returns true
    • CountUntil - Returns the number of elements in an InputRange until the callback returns true.
    • CommonPrefix - Returns a FowardRange over the common prefix of two ranges. The first range must be a ForwardRange.
    • DropWhile - Advances a range while a callback returns true.
    • Find - Advances a range until cb(x, needle) returns true, comparing elements with a needle.
    • FindComparable - Advances a range until x == needle.
    • FindEqual - Advances a range until cb(a, b) returns true for every element of a needle range.
    • FindEqualComparable - Advances a range until a == b is satisfied for all elements of a needle range.
    • FindAdjacent - Advances a range until cb(a, b) returns true for two adjacent elements in a ForwardRange.
    • FindAdjacentComparable - Advances a range until a == b is satisfied for two adjacent elements in a ForwardRange.
    • FindAmong - Advances a range until cb(a, b) returns true for any element of a needle range.
    • FindAmongComparable - Advances a range until a == b is satisfied for any element of a needle range.
    • SkipOver - Skips over elements in a haystack ForwardRange if the range starts with a needle range, according to cb(a, b) == true.
    • StartsWith - Checks if one InputRange starts with another one, through a callback.
    • TakeWhile - Advances a range until the callback returns true.
  • setops
    • CartesianProduct - Computes the Cartesian product of a series of forward ranges.

Implementing New Ranges

New Ranges can be implemented by creating a struct with pointer receivers for all of the methods needed to satisfy a type of range. For example:

// A pointer to this is an InputRange[T] because of the implementation below.
type newRangeType[T any] struct {
  // Add whatever data you need.
}

func (r *newRangeType[T]) Empty() bool { /* ... */ }
func (r *newRangeType[T]) Front() T    { /* ... */ }
func (r *newRangeType[T]) PopFront()   { /* ... */ }

func MakeNewRangeType[T any](/* ... */) InputRange[T] {
  return &newRangeType{/* ... */}
}

It's important to return pointers to your structs so ranges can be freely passed around as a reference type.

Performance

Wherever possible, algorithms will attempt to minimize allocations. The Len() of any RandomAccessRange objects at runtime, or the len() of slices may be used to determine how much memory to allocate, or to optimize algorithms to avoid unnecessary operations.

Go's compiler is capable of inlining many range function calls, which will reduce overhead. Ranges are likely to be stored in the garbage-collected heap. The performance of using ranges will therefore be hard to predict. You should benchmark and debug your code, and add optimizations where appropriate. Significant improvements easily obtained are never premature.

Limitations

No function overloading for generic types

It's not possible to implement a Filter function that returns ForwardRange[T] if given ForwardRange[T] and returns InputRange[T] if given InputRange[T].

The only available alternative in Go is to write multiple function names for each range type, such as FilterF for ForwardRange[T] and Filter for InputRange[T].

No covariant return types in Go

For the definition of a BidirectionalRange and RandomAccessRange, we would require the following.

type BidirectionalRange[T any] interface {
    ForwardRange[T]
    Save() BidirectionalRange[T]
    Back() T
    PopBack()
}

type RandomAccessRange[T any] interface {
    BidirectionalRange[T]
    Save() RandomAccessRange[T]
    GetIndex(index int) T
}

This is not possible in Go because Save() cannot be implemented with multiple return types, and the interfaces cannot be re-implemented with InputRange[T] as a basis because that means Go will not consider either type to be a subtype of ForwardRange[T].

This library could be extended so we represent types like so:

type BidirectionalRange[T any] interface {
	ForwardRange[T]
	SaveB() BidirectionalRange[T]
	Back() T
	PopBack()
}

type RandomAccessRange[T any] interface {
	BidirectionalRange[T]
	Get(index int) T
	SaveR() RandomAccessRange[T]
}

type RandomAccessRangeWithLength[T any] interface {
	RandomAccessRange[T]
	HasLength
	SaveRL() RandomAccessRangeWithLength[T]
}

Then supporting those range types would only require redundantly defining Save as up to 4 different methods with slightly different names to get the more specific types. This would be mildly annoying, but would work.

Weak inference of ForwardRange[T] as InputRange[T] before Go 1.21

You cannot write the following in Go versions below 1.21:

r := Only(1, 2, 3, 4)
sliceCopy := Slice(Filter(r, func(element int) bool { return element % 2 == 0 }))
\\                      ^ Go can't take T from ForwardRange[T]

But the following is fine:

r := Only(1, 2, 3, 4)
sliceCopy := Slice(Filter[int](r, func(element int) bool { return element % 2 == 0 }))
\\                       ^ Now Go knows T and we can pass ForwardRange[T]

Go 1.2.1 fixed this issue by adding better type inference, so the former case should just work in Go 1.21.

For this reason variations of the functions exist to require less typing.

r := Only(1, 2, 3, 4)
sliceCopy := SliceF(FilterF(r, func(element int) bool { return element % 2 == 0 }))
\\                ^       ^ We accept ForwardRanges, so Go figures it out.
No tuple types and variadic generics

Variadic generic types are difficult to implement correctly, and Go does not have generic tuple types to represent any combination of values. This means that just as in classic Java generic interfaces, functions that take different combinations of types must be redundantly defined up to some maximum number of arguments in a programmer's imagination of how many arguments someone will call a function with. For example:

func Args0()[] { }
func Args1[V1 any](v1 V1) { }
func Args2[V1 any, V2](v1 V1, v2 V2) { }
func Args3[V1 any, V2 any, V3 any](v1 V1, v2 V2, v3 V3) { }
func Args3[V1 any, V2 any, V3 any, V4 any](v1 V1, v2 V2, v3 V3, v4 V4) { }

It's not possible to write something like the following for all of the above:

func Args[V any...](v V...) { }

Because of this, multiple variations of the Zip function are required.

Advantages of Go

Exceptions must be an explicit part of the type of ranges

Go does not have exceptions outside of panic. Ranges that can yield errors at any point have to explicitly include them in the type of result returned by Front(), so all ranges should be considered exception safe as long as the contract of calling Empty() before Front() or PopFront() is not broken.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](r InputRange[T], cb func(element T) bool) bool

All returns true if `cb` returns `true` for all elements

func AllS

func AllS[T any](r []T, cb func(element T) bool) bool

AllS is `All` accepting a slice.

func Among

func Among[T any](eq func(a, b T) bool, value T, values ...T) bool

Among returns `true` is `value` is equal to any of the `values` according to `eq`

func AmongEq

func AmongEq[T comparable](value T, values ...T) bool

AmongEq implements `Among` with `==` for any comparable type.

func Any

func Any[T any](r InputRange[T], cb func(element T) bool) bool

Any returns true if `cb` returns `true` for any element

func AnyS

func AnyS[T any](r []T, cb func(element T) bool) bool

AnyS is `Any` accepting a slice.

func CanFind

func CanFind[T any](haystack InputRange[T], cb func(a, b T) bool, needle T) bool

CanFind returns `true` if `cb(a, b) == true`, comparing with needle.

func CanFindComparable

func CanFindComparable[T comparable](haystack InputRange[T], needle T) bool

CanFindComparable returns `true` if `a == b`, comparing with needle.

func CanFindComparableS

func CanFindComparableS[T comparable](haystack []T, needle T) bool

CanFindComparableS is CanFindComparable accepting a slice.

func CanFindS

func CanFindS[T any](haystack []T, cb func(a, b T) bool, needle T) bool

CanFindS is `CanFind` accepting a slice.

func Cmp

func Cmp[T any](r1 InputRange[T], r2 InputRange[T], cmp func(a, b T) int) int

Cmp iterates `r1` and `r2` in lockstep and compares values with the `cmp` function.

The first non-zero result is returned.

-1 is returned if the first range is smaller and all elements are equal. 1 is returned if the second range is smaller and all elements are equal.

func CmpFunc

func CmpFunc[T Ordered](a, b T) int

CmpFunc produces a comparison function for any orderable type.

func Compose10

func Compose10[A, B, C, D, E, F, G, H, I, J, K any](
	f1 func(x J) K,
	f2 func(x I) J,
	f3 func(x H) I,
	f4 func(x G) H,
	f5 func(x F) G,
	f6 func(x E) F,
	f7 func(x D) E,
	f8 func(x C) D,
	f9 func(x B) C,
	f10 func(x A) B,
) func(x A) K

func Compose2

func Compose2[A, B, C any](f1 func(x B) C, f2 func(x A) B) func(x A) C

func Compose3

func Compose3[A, B, C, D any](
	f1 func(x C) D,
	f2 func(x B) C,
	f3 func(x A) B,
) func(x A) D

func Compose4

func Compose4[A, B, C, D, E any](
	f1 func(x D) E,
	f2 func(x C) D,
	f3 func(x B) C,
	f4 func(x A) B,
) func(x A) E

func Compose5

func Compose5[A, B, C, D, E, F any](
	f1 func(x E) F,
	f2 func(x D) E,
	f3 func(x C) D,
	f4 func(x B) C,
	f5 func(x A) B,
) func(x A) F

func Compose6

func Compose6[A, B, C, D, E, F, G any](
	f1 func(x F) G,
	f2 func(x E) F,
	f3 func(x D) E,
	f4 func(x C) D,
	f5 func(x B) C,
	f6 func(x A) B,
) func(x A) G

func Compose7

func Compose7[A, B, C, D, E, F, G, H any](
	f1 func(x G) H,
	f2 func(x F) G,
	f3 func(x E) F,
	f4 func(x D) E,
	f5 func(x C) D,
	f6 func(x B) C,
	f7 func(x A) B,
) func(x A) H

func Compose8

func Compose8[A, B, C, D, E, F, G, H, I any](
	f1 func(x H) I,
	f2 func(x G) H,
	f3 func(x F) G,
	f4 func(x E) F,
	f5 func(x D) E,
	f6 func(x C) D,
	f7 func(x B) C,
	f8 func(x A) B,
) func(x A) I

func Compose9

func Compose9[A, B, C, D, E, F, G, H, I, J any](
	f1 func(x I) J,
	f2 func(x H) I,
	f3 func(x G) H,
	f4 func(x F) G,
	f5 func(x E) F,
	f6 func(x D) E,
	f7 func(x C) D,
	f8 func(x B) C,
	f9 func(x A) B,
) func(x A) J

func Copy

func Copy[T any](input InputRange[T], output OutputRange[T]) error

Copy copies all values from an InputRange into an OutputRange

func Count

func Count[T any](r InputRange[T], cb func(element T) bool) int

Count returns the number of elements where `cb` returns `true`

func CountUntil

func CountUntil[T any](r InputRange[T], cb func(element T) bool) int

CountUntil returns the number of elements until `cb` returns `true`

func Each

func Each[T any](r InputRange[T], cb func(element T))

Each calls the callback with each element of the range.

func EachS

func EachS[T any](r []T, cb func(element T))

EachS is `Each` accepting a slice.

func Eq

func Eq[T comparable](a, b T) bool

Eq returns a == b

func Equal

func Equal[T any](r1, r2 InputRange[T], cb func(a, b T) bool) bool

Runtime type conversions will be applied to check the length of both ranges if both are RandomAccessRange instances, to avoid stepping through the ranges if the lengths differ.

func EqualComparable

func EqualComparable[T comparable](r1, r2 InputRange[T]) bool

EqualComparable returns `true` if two ranges of `comparable` values are equal.

Runtime type conversions will be applied to check the length of both ranges if both are RandomAccessRange instances, to avoid stepping through the ranges if the lengths differ.

func EqualComparableS

func EqualComparableS[T comparable](r1, r2 []T) bool

EqualComparableS returns `true` if two slices of `comparable` values are equal.

func EqualS

func EqualS[T any](r1, r2 []T, cb func(a, b T) bool) bool

EqualS returns `true` if two slices of are equal according to `cb`

func Exhaust

func Exhaust[T any](r InputRange[T])

Exhaust steps through every element of a range until the range is empty.

Front() will never be called in the range.

func Fill

func Fill[T any](r InputRange[*T], value T)

Fill assigns the given value to the locations of all addresses in a range.

func FillPattern

func FillPattern[T any](r InputRange[*T], pattern ForwardRange[T])

FillPattern assigns a pattern of values to the locations of all addresses in a range.

func Ge

func Ge[T Ordered](a, b T) bool

Ge returns a >= b

func Gt

func Gt[T Ordered](a, b T) bool

Gt returns a > b

func IsPermutation

func IsPermutation[T comparable](r1 InputRange[T], r2 InputRange[T]) bool

IsPermutation returns `true` if two ranges are permutations of each other by allocating a temporary map.

func IsPermutationNoAlloc

func IsPermutationNoAlloc[T comparable](r1 ForwardRange[T], r2 ForwardRange[T]) bool

IsPermutationNoAlloc returns `true` if two ranges are permutations of each other in O(m * n) time without allocating any new memory itself.

func IsSameLength

func IsSameLength[T any, U any](r1 InputRange[T], r2 InputRange[U]) bool

IsSameLength returns `true` if two ranges have the same length in O(n) time.

The ranges are exhausted.

If you have access to random access ranges, use `r1.Len() == r2.Len()` instead.

func JoinStrings

func JoinStrings(r ForwardRange[string], separator string) string

JoinStrings joins a range of strings together as one string.

func Le

func Le[T Ordered](a, b T) bool

Le returns a <= b

func Length

func Length[T any](r InputRange[T]) int

Length returns the length of a range in O(n) time.

The range is exhausted.

If your range is a RandomAccessRange, use `r.Len()` instead.

func Lt

func Lt[T Ordered](a, b T) bool

Lt returns a < b

func Max

func Max[T Ordered](v1, v2 T, values ...T) T

Max returns the maximum value among provided arguments.

func Min

func Min[T Ordered](v1, v2 T, values ...T) T

Min returns the minimum value among provided arguments.

func Ne

func Ne[T comparable](a, b T) bool

Ne returns a != b

func Pipe10

func Pipe10[A, B, C, D, E, F, G, H, I, J, K any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
	f6 func(x F) G,
	f7 func(x G) H,
	f8 func(x H) I,
	f9 func(x I) J,
	f10 func(x J) K,
) func(x A) K

func Pipe2

func Pipe2[A, B, C any](f1 func(x A) B, f2 func(x B) C) func(x A) C

func Pipe3

func Pipe3[A, B, C, D any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
) func(x A) D

func Pipe4

func Pipe4[A, B, C, D, E any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
) func(x A) E

func Pipe5

func Pipe5[A, B, C, D, E, F any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
) func(x A) F

func Pipe6

func Pipe6[A, B, C, D, E, F, G any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
	f6 func(x F) G,
) func(x A) G

func Pipe7

func Pipe7[A, B, C, D, E, F, G, H any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
	f6 func(x F) G,
	f7 func(x G) H,
) func(x A) H

func Pipe8

func Pipe8[A, B, C, D, E, F, G, H, I any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
	f6 func(x F) G,
	f7 func(x G) H,
	f8 func(x H) I,
) func(x A) I

func Pipe9

func Pipe9[A, B, C, D, E, F, G, H, I, J any](
	f1 func(x A) B,
	f2 func(x B) C,
	f3 func(x C) D,
	f4 func(x D) E,
	f5 func(x E) F,
	f6 func(x F) G,
	f7 func(x G) H,
	f8 func(x H) I,
	f9 func(x I) J,
) func(x A) J

func Reduce

func Reduce[T, U any](r InputRange[T], cb func(a U, b T) U, seed U) U

Reduce produces a singe value from a range by calling a callback to combine the values. The seed value will be used as the first value for `a` in `cb(a, b)`.

func ReduceNoSeed

func ReduceNoSeed[T any](r InputRange[T], cb func(a T, b T) T) T

ReduceNoSeed is `Reduce` where the the range is assumed not to be empty, and the seed is the front of the range.

Panics when the range is empty.

func ReduceNoSeedS

func ReduceNoSeedS[T any](r []T, cb func(a T, b T) T) T

ReduceNoSeedS is `ReduceNoSeed` accepting a slice.

func ReduceS

func ReduceS[T, U any](r []T, cb func(a U, b T) U, seed U) U

ReduceS is `Reduce` accepting a slice.

func SkipOver

func SkipOver[T any, U any](
	haystack *ForwardRange[T],
	needle InputRange[U],
	cb func(element1 T, element2 U) bool,
) bool

SkipOver sets `haystack` to the range after `needle`, if and only if `haystack` starts with `needle`.

func Slice

func Slice[T any](r InputRange[T]) []T

Slice creates a slice of memory from a range. If the type of the range at runtime is a RandomAccessRange, the Len() will be used to allocate the slice up-front.

func SliceB

func SliceB[T any](r BidirectionalRange[T]) []T

SliceB is `Slice` accepting a BidirectionalRange.

func SliceF

func SliceF[T any](r ForwardRange[T]) []T

SliceF is `Slice` accepting a ForwardRange.

func SliceR added in v0.4.0

func SliceR[T any](r RandomAccessRange[T]) []T

SliceR is `Slice` accepting a RandomAccessRange. This variant will allocate the slice with the length of the range without casting the type.

func StartsWith

func StartsWith[T any, U any](
	r1 InputRange[T],
	r2 InputRange[U],
	cb func(element1 T, element2 U) bool,
) bool

StartsWith returns `true` if `r1` starts with `r2` according to `cb`

func String

func String(r InputRange[rune]) string

String creates a new string from a range of runes.

func StringB

func StringB(r BidirectionalRange[rune]) string

StringB is `String` accepting a BidirectionalRange.

func StringF

func StringF(r ForwardRange[rune]) string

StringF is `String` accepting a ForwardRange.

func StringR added in v0.4.0

func StringR(r RandomAccessRange[rune]) string

StringR is `String` accepting a RandomAccessRange. This variant is specialized so the rune slice will be allocated with the `Len()` of the range.

func StringS

func StringS(r []rune) string

StringS is `String` accepting a slice of runes.

This can be used as a callback where `string` cannot be.

Types

type BidirectionalRange

type BidirectionalRange[T any] interface {
	ForwardRange[T]
	Back() T
	PopBack()
	SaveB() BidirectionalRange[T]
}

BidirectionalRange is a ForwardRange that can be accessed from both directions.

func B added in v0.4.0

B is a convenience function for passing a RandomAccessRange as a BidirectionalRange

func CacheB

func CacheB[T any](r BidirectionalRange[T]) BidirectionalRange[T]

CacheB is `CacheF` for bidrectional ranges.

Traversing in both directions could cause the same expression to be evaluated twice. If the range is saved, `Front()` or `Back()` will be called multiple times.

func ChainB

func ChainB[T any](ranges ...BidirectionalRange[T]) BidirectionalRange[T]

ChainB is `ChainF` that can be shrunk from the back.

func ChainS

func ChainS[T any](ranges ...[]T) BidirectionalRange[T]

ChainS is `ChainB` accepting many slices.

func DropB

func DropB[T any](r BidirectionalRange[T], count int) BidirectionalRange[T]

DropB is `DropF` that can be shrunk from the back.

func FilterB

func FilterB[T any](r BidirectionalRange[T], cb func(element T) bool) BidirectionalRange[T]

FilterB is `FilterF` that can move in both directions.

This is less efficient for moving forward than `FilterF`, as the filtered range must be primed in both directions.

func FilterSB

func FilterSB[T any](slice []T, cb func(element T) bool) BidirectionalRange[T]

FilterS is `FilterB` accepting a slice.

This is less efficient for moving forward than `FilterS`, as the filtered range must be primed in both directions.

func FlattenB

FlattenB is `FlattenF` that can be shrunk from the back.

func FlattenSB

func FlattenSB[T any](r []BidirectionalRange[T]) BidirectionalRange[T]

FlattenSB is `FlattenS` for bidirectional ranges.

func FlattenSS

func FlattenSS[T any](r [][]T) BidirectionalRange[T]

FlattenSS is `FlattenB` accepting a slice of slices.

func FrontTransversalB

func FrontTransversalB[T any](r BidirectionalRange[BidirectionalRange[T]]) BidirectionalRange[T]

FrontTransversalB is `FrontTransversalF` that can be shrunk from the back.

func Generate

func Generate[T any](cb func() T) BidirectionalRange[T]

Generate genereates a value infinitely by calling a function

func Iota

func Iota[T RealNumber](end T) BidirectionalRange[T]

Iota returns a range of values from 0 to `end`, excluding `end`, incrementing by `1`

func IotaStart

func IotaStart[T RealNumber](begin, end T) BidirectionalRange[T]

IotaStart returns a range of values from `begin` to `end`, excluding `end`, incrementing by `1`

func IotaStep

func IotaStep[T RealNumber](begin, end, step T) BidirectionalRange[T]

IotaStep returns a range of values from `begin` to `end`, excluding `end`, incrementing by `step`

func MapB

func MapB[T any, U any](r BidirectionalRange[T], cb func(a T) U) BidirectionalRange[U]

MapB is `MapF` that can be shrunk from the back.

`cb` will be called each time `Back()` is called.

The `Cache` function can be used to cache the result when generating ranges.

func Repeat

func Repeat[T any](value T) BidirectionalRange[T]

Repeat repeats a value infinitely

func Retro

func Retro[T any](r BidirectionalRange[T]) BidirectionalRange[T]

Retro iterates a BidirectionalRange in reverse.

func Strip

func Strip[T any](r BidirectionalRange[T], cb func(a T) bool) BidirectionalRange[T]

Strip removes elements where `cb(a) == true` from the front and back of a range.

func StripComparable

func StripComparable[T comparable](r BidirectionalRange[T], value T) BidirectionalRange[T]

StripComparable removes elements equal to `value` from the front and back of a range.

func StripLeftB

func StripLeftB[T any](r BidirectionalRange[T], cb func(a T) bool) BidirectionalRange[T]

StripLeftB is `StripLeftF` that can be shrunk from the back.

func StripLeftComparableB

func StripLeftComparableB[T comparable](r BidirectionalRange[T], value T) BidirectionalRange[T]

StripLeftComparableB is `StripLeftComparableF` where the range can be shrunk from the back.

func StripRight

func StripRight[T any](r BidirectionalRange[T], cb func(a T) bool) BidirectionalRange[T]

StripRight removes elements where `cb(a) == true` from the back of a range.

func StripRightComparable

func StripRightComparable[T comparable](r BidirectionalRange[T], value T) BidirectionalRange[T]

StripRightComparable removes elements equal to `value` from the back of a range.

func UniqB

func UniqB[T any](r BidirectionalRange[T], cb func(a, b T) bool) BidirectionalRange[T]

UniqB is `UniqF` that can be shrunk from the back.

func UniqComparableB

func UniqComparableB[T comparable](r BidirectionalRange[T]) BidirectionalRange[T]

UniqComparableB is `UniqComparableF` that can be shrunk from the back.

func UniqComparableS

func UniqComparableS[T comparable](r []T) BidirectionalRange[T]

UniqComparableS is `UniqComparableB` accepting a slice.

func UniqS

func UniqS[T any](r []T, cb func(a, b T) bool) BidirectionalRange[T]

UniqS is `UniqB` accepting a slice.

type Decade

type Decade[A, B, C, D, E, F, G, H, I, J any] struct {
	A A
	B B
	C C
	D D
	E E
	F F
	G G
	H H
	I I
	J J
}

Decade holds 10 items

func MakeDecade

func MakeDecade[A, B, C, D, E, F, G, H, I, J any](a A, b B, c C, d D, e E, f F, g G, h H, i I, j J) Decade[A, B, C, D, E, F, G, H, I, J]

MakeDecade creates a Decade

func (Decade[A, B, C, D, E, F, G, H, I, J]) Get added in v0.3.0

func (d Decade[A, B, C, D, E, F, G, H, I, J]) Get() (A, B, C, D, E, F, G, H, I, J)

Get returns items as a Go tuple

type Ennead

type Ennead[A, B, C, D, E, F, G, H, I any] struct {
	A A
	B B
	C C
	D D
	E E
	F F
	G G
	H H
	I I
}

Ennead holds 9 items

func MakeEnnead

func MakeEnnead[A, B, C, D, E, F, G, H, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Ennead[A, B, C, D, E, F, G, H, I]

MakeEnnead creates a Ennead

func (Ennead[A, B, C, D, E, F, G, H, I]) Get added in v0.3.0

func (e Ennead[A, B, C, D, E, F, G, H, I]) Get() (A, B, C, D, E, F, G, H, I)

Get returns items as a Go tuple

type Float

type Float interface {
	~float32 | ~float64
}

Float is any floating point type.

type ForwardRange

type ForwardRange[T any] interface {
	InputRange[T]
	Save() ForwardRange[T]
}

ForwardRange is an InputRange you can save the position of.

func CacheF

func CacheF[T any](r ForwardRange[T]) ForwardRange[T]

CacheF is `Cache` for forward ranges.

If the range is traversed once, `Front()` will be called once per element. If the range is saved, `Front()` will be called multiple times.

func CartesianProduct10

func CartesianProduct10[A, B, C, D, E, F, G, H, I, J any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
	r6 ForwardRange[F],
	r7 ForwardRange[G],
	r8 ForwardRange[H],
	r9 ForwardRange[I],
	r10 ForwardRange[J],
) ForwardRange[Decade[A, B, C, D, E, F, G, H, I, J]]

CartesianProduct10 produces the cartersian product r1 X r2 X r3 X r4 X r5 X r6 x r7 x r8 x r9 x r10

func CartesianProduct2

func CartesianProduct2[A, B any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
) ForwardRange[Pair[A, B]]

CartesianProduct2 produces the cartersian product r1 X r2

func CartesianProduct3

func CartesianProduct3[A, B, C any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
) ForwardRange[Triplet[A, B, C]]

CartesianProduct3 produces the cartersian product r1 X r2 X r3

func CartesianProduct4

func CartesianProduct4[A, B, C, D any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
) ForwardRange[Quartet[A, B, C, D]]

CartesianProduct4 produces the cartersian product r1 X r2 X r3 X r4

func CartesianProduct5

func CartesianProduct5[A, B, C, D, E any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
) ForwardRange[Quintet[A, B, C, D, E]]

CartesianProduct5 produces the cartersian product r1 X r2 X r3 X r4 X r5

func CartesianProduct6

func CartesianProduct6[A, B, C, D, E, F any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
	r6 ForwardRange[F],
) ForwardRange[Sextet[A, B, C, D, E, F]]

CartesianProduct6 produces the cartersian product r1 X r2 X r3 X r4 X r5 X r6

func CartesianProduct7

func CartesianProduct7[A, B, C, D, E, F, G any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
	r6 ForwardRange[F],
	r7 ForwardRange[G],
) ForwardRange[Septet[A, B, C, D, E, F, G]]

CartesianProduct7 produces the cartersian product r1 X r2 X r3 X r4 X r5 X r6 x r7

func CartesianProduct8

func CartesianProduct8[A, B, C, D, E, F, G, H any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
	r6 ForwardRange[F],
	r7 ForwardRange[G],
	r8 ForwardRange[H],
) ForwardRange[Octet[A, B, C, D, E, F, G, H]]

CartesianProduct8 produces the cartersian product r1 X r2 X r3 X r4 X r5 X r6 x r7 x r8

func CartesianProduct9

func CartesianProduct9[A, B, C, D, E, F, G, H, I any](
	r1 ForwardRange[A],
	r2 ForwardRange[B],
	r3 ForwardRange[C],
	r4 ForwardRange[D],
	r5 ForwardRange[E],
	r6 ForwardRange[F],
	r7 ForwardRange[G],
	r8 ForwardRange[H],
	r9 ForwardRange[I],
) ForwardRange[Ennead[A, B, C, D, E, F, G, H, I]]

CartesianProduct9 produces the cartersian product r1 X r2 X r3 X r4 X r5 X r6 x r7 x r8 x r9

func ChainF

func ChainF[T any](ranges ...ForwardRange[T]) ForwardRange[T]

ChainF is `Chain` where the range can be saved.

func ChunksF

func ChunksF[T any](r ForwardRange[T], size int) ForwardRange[ForwardRange[T]]

`ChunksF` is `Chunks` where the range can be saved.

func CommonPrefix

func CommonPrefix[T any, U any](
	r1 ForwardRange[T],
	r2 InputRange[U],
	cb func(element1 T, element2 U) bool,
) ForwardRange[T]

CommonPrefix returns `true` if `r1` starts with `r2` according to `cb`

func CommonPrefixF

func CommonPrefixF[T any, U any](
	r1 ForwardRange[T],
	r2 ForwardRange[U],
	cb func(element1 T, element2 U) bool,
) ForwardRange[T]

CommonPrefixF is `CommonPrefix` accepting a second forward range.

func CommonPrefixS

func CommonPrefixS[T any, U any](r1 []T, r2 []U, cb func(element1 T, element2 U) bool) ForwardRange[T]

CommonPrefixS is `CommonPrefix` accepting slices.

func Cycle

func Cycle[T any](r ForwardRange[T]) ForwardRange[T]

Cycle repeats a ForwardRange infinitely.

func DropF

func DropF[T any](r ForwardRange[T], count int) ForwardRange[T]

DropF is `Drop` where the range can be saved.

func DropWhileF

func DropWhileF[T any](r ForwardRange[T], cb func(element T) bool) ForwardRange[T]

DropWhileF is DropWhile where the range can be saved.

func EnumerateF

func EnumerateF[T any](r ForwardRange[T]) ForwardRange[Pair[int, T]]

EnumerateF is `Enumerate` where the range can be saved.

func EnumerateNF

func EnumerateNF[T any](r ForwardRange[T], n int) ForwardRange[Pair[int, T]]

EnumerateNF is `EnumerateN` where the range can be saved.

func F

func F[T any](r BidirectionalRange[T]) ForwardRange[T]

F is a convenience function for passing a BidirectionalRange as a ForwardRange

func FilterF

func FilterF[T any](r ForwardRange[T], cb func(element T) bool) ForwardRange[T]

FilterF is `Filter` where the range can be saved.

func FilterS

func FilterS[T any](slice []T, cb func(element T) bool) ForwardRange[T]

FilterS is `FilterF` accepting a slice.

Returns a ForwardRange, which is more efficient when moving forwards. `FilterSB` can be advanced in both directions.

func FindAdjacent

func FindAdjacent[T any](haystack ForwardRange[T], cb func(a, b T) bool) ForwardRange[T]

FindAdjacent advances a range until cb(a, b) returns `true` for two adjacent elements.

func FindAdjacentComparable

func FindAdjacentComparable[T comparable](haystack ForwardRange[T]) ForwardRange[T]

FindAdjacentComparable advances a range until a == b for two adjacent elements.

func FindAdjacentComparableS

func FindAdjacentComparableS[T comparable](haystack []T) ForwardRange[T]

FindAdjacentComparableS is FindAdjacentComparable accepting a slice.

func FindAdjacentS

func FindAdjacentS[T any](haystack []T, cb func(a, b T) bool) ForwardRange[T]

FindAdjacentS is FindAdjacent accepting a slice.

func FindAmongComparableF

func FindAmongComparableF[T comparable](haystack ForwardRange[T], needle ForwardRange[T]) ForwardRange[T]

FindAmongComparableF is FindAmongComparable where the range can be saved.

func FindAmongComparableS

func FindAmongComparableS[T comparable](haystack []T, needle ForwardRange[T]) ForwardRange[T]

FindAmongComparableS is FindAmongComparableF accepting a slice.

func FindAmongF

func FindAmongF[T any](haystack ForwardRange[T], cb func(a, b T) bool, needle ForwardRange[T]) ForwardRange[T]

FindAmongF is FindAmong where the range can be saved.

func FindAmongS

func FindAmongS[T any](haystack []T, cb func(a, b T) bool, needle ForwardRange[T]) ForwardRange[T]

FindAmongS is FindAmongF accepting a slice.

func FindComparableF

func FindComparableF[T comparable](haystack ForwardRange[T], needle T) ForwardRange[T]

FindComparableF is `FindComparable` where the range can be saved.

func FindComparableS

func FindComparableS[T comparable](haystack []T, needle T) ForwardRange[T]

FindComparableS is `FindComparableF` accepting a slice.

func FindEqual

func FindEqual[T any](haystack ForwardRange[T], cb func(a, b T) bool, needle ForwardRange[T]) ForwardRange[T]

FindEqual advances a range until cb(a, b) returns `true` for all elments of `needle`.

func FindEqualComparable

func FindEqualComparable[T comparable](haystack ForwardRange[T], needle ForwardRange[T]) ForwardRange[T]

FindEqualComparable advances a range until `a == b` is satisifed for all elements of a `needle`.

func FindEqualComparableS

func FindEqualComparableS[T comparable](haystack []T, needle ForwardRange[T]) ForwardRange[T]

FindEqualComparableS is FindEqualComparable accepting a slice.

func FindEqualS

func FindEqualS[T any](haystack []T, cb func(a, b T) bool, needle ForwardRange[T]) ForwardRange[T]

FindEqualS is FindEqual accepting a slice.

func FindF

func FindF[T any](haystack ForwardRange[T], cb func(a, b T) bool, needle T) ForwardRange[T]

FindF is `Find` where the range can be saved.

func FindS

func FindS[T any](haystack []T, cb func(a, b T) bool, needle T) ForwardRange[T]

FindS is `FindF` accepting a slice.

func FlattenF

func FlattenF[T any](r ForwardRange[ForwardRange[T]]) ForwardRange[T]

FlattenF is `Flatten` where the range can be saved.

func FlattenS

func FlattenS[T any](r []ForwardRange[T]) ForwardRange[T]

FlattenS is `FlattenF` accepting a slice.

func FrontTransversalF

func FrontTransversalF[T any](r ForwardRange[ForwardRange[T]]) ForwardRange[T]

FrontTransversalF is `FrontTransversal` where the range can be saved.

func JoinerF

func JoinerF[T any](r ForwardRange[ForwardRange[T]], separator ForwardRange[T]) ForwardRange[T]

JoinerF is `Joiner`, where the position can be saved.

func JoinerS

func JoinerS[T any](r []ForwardRange[T], separator ForwardRange[T]) ForwardRange[T]

JoinerS is `JoinerF` accepting a slice of ranges.

func JoinerSS

func JoinerSS[T any](r [][]T, separator []T) ForwardRange[T]

JoinerSS is `JoinerF` accepting a slice of lisces.

func MapF

func MapF[T any, U any](r ForwardRange[T], cb func(a T) U) ForwardRange[U]

MapF is `Map`, where the position can be saved.

func PadRightF

func PadRightF[T any](r ForwardRange[T], value T, count int) ForwardRange[T]

PadRightF is `PadRight` returning a ForwardRange

func PadRightS

func PadRightS[T any](r []T, value T, count int) ForwardRange[T]

PadRightS is `PadRightF` accepting a slice

func Permutations

func Permutations[T any](r []T) ForwardRange[[]T]

Permutations returns all permutations of a slice in a forward range.

func RoundRobinF

func RoundRobinF[T any](ranges ...ForwardRange[T]) ForwardRange[T]

RoundRobinF is `RoundRobin` producing a ForwardRange

func Slide

func Slide[T any](r ForwardRange[T], windowSize int) ForwardRange[ForwardRange[T]]

Slide yields chunks starting from every element in a range.

This function will panic `if windowSize < 1`.

func SlideS

func SlideS[T any](r []T, windowSize int) ForwardRange[ForwardRange[T]]

SlideS is `Slide` accepting a slice.

func SlideStep

func SlideStep[T any](r ForwardRange[T], windowSize int, stepSize int) ForwardRange[ForwardRange[T]]

SlideStep is `Slide` steping over elements with a given `stepSize`

func SlideStepS

func SlideStepS[T any](r []T, windowSize int, stepSize int) ForwardRange[ForwardRange[T]]

SlideStepS is `Slide` accepting a slice.

func SplitString

func SplitString(r string, separator string) ForwardRange[string]

SplitString splits a string by a `separator` into a range of strings.

func Splitter

func Splitter[T any](r ForwardRange[T], cb func(a, b T) bool, separator ForwardRange[T]) ForwardRange[ForwardRange[T]]

Splitter splits a range using a ForwardRange as a separator where `cb(a, b) == true` on each element.

func SplitterComparable

func SplitterComparable[T comparable](r ForwardRange[T], separator ForwardRange[T]) ForwardRange[ForwardRange[T]]

SplitterComparable splits ranges using a ForwardRange as a separator where each element is equal.

func SplitterComparableS

func SplitterComparableS[T comparable](r []T, separator ForwardRange[T]) ForwardRange[ForwardRange[T]]

SplitterComparableS is `SplitterComparable` accepting a slice.

func SplitterComparableSS

func SplitterComparableSS[T comparable](r []T, separator []T) ForwardRange[ForwardRange[T]]

SplitterComparableSS is `SplitterComparable` accepting a slice for both ranges

func SplitterS

func SplitterS[T any](r []T, cb func(a, b T) bool, separator ForwardRange[T]) ForwardRange[ForwardRange[T]]

SplitterS is `Splitter` accepting a slice.

func SplitterSS

func SplitterSS[T any](r []T, cb func(a, b T) bool, separator []T) ForwardRange[ForwardRange[T]]

SplitterSS is `SplitterS` accepting a slice for both ranges.

func StrideF

func StrideF[T any](r ForwardRange[T], step int) ForwardRange[T]

StrideF is `Stride` producing a `ForwardRange`

func StrideS

func StrideS[T any](r []T, step int) ForwardRange[T]

StrideS is `StrideF` accepting a slice.

This result is optimized for slices.

func StripLeftComparableF

func StripLeftComparableF[T comparable](r ForwardRange[T], value T) ForwardRange[T]

StripLeftComparableF is `StripLeftComparable` where the position can be saved.

func StripLeftF

func StripLeftF[T any](r ForwardRange[T], cb func(a T) bool) ForwardRange[T]

StripLeftF is `StripLeft` where the position can be saved.

func TakeF

func TakeF[T any](r ForwardRange[T], count int) ForwardRange[T]

TakeF is `Take` where the range can be saved.

func TakeWhileF

func TakeWhileF[T any](r ForwardRange[T], cb func(element T) bool) ForwardRange[T]

TakeWhileF is `TakeWhile` producing a `ForwardRange`

func UniqComparableF

func UniqComparableF[T comparable](r ForwardRange[T]) ForwardRange[T]

UniqComparableF is `UniqComparable` where the range can be saved.

func UniqF

func UniqF[T any](r ForwardRange[T], cb func(a, b T) bool) ForwardRange[T]

UniqF is `Uniq` where the range can be saved.

func Zip10F

func Zip10F[A, B, C, D, E, F, G, H, I, J any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
	f ForwardRange[F],
	g ForwardRange[G],
	h ForwardRange[H],
	i ForwardRange[I],
	j ForwardRange[J],
) ForwardRange[Decade[A, B, C, D, E, F, G, H, I, J]]

Zip10F produces items from 10 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip2F

func Zip2F[A, B any](
	a ForwardRange[A],
	b ForwardRange[B],
) ForwardRange[Pair[A, B]]

Zip2F produces items from 2 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip3F

func Zip3F[A, B, C any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
) ForwardRange[Triplet[A, B, C]]

Zip3F produces items from 3 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip4F

func Zip4F[A, B, C, D any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
) ForwardRange[Quartet[A, B, C, D]]

Zip4F produces items from 4 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip5F

func Zip5F[A, B, C, D, E any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
) ForwardRange[Quintet[A, B, C, D, E]]

Zip5F produces items from 5 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip6F

func Zip6F[A, B, C, D, E, F any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
	f ForwardRange[F],
) ForwardRange[Sextet[A, B, C, D, E, F]]

Zip6F produces items from 6 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip7F

func Zip7F[A, B, C, D, E, F, G any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
	f ForwardRange[F],
	g ForwardRange[G],
) ForwardRange[Septet[A, B, C, D, E, F, G]]

Zip7F produces items from 7 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip8F

func Zip8F[A, B, C, D, E, F, G, H any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
	f ForwardRange[F],
	g ForwardRange[G],
	h ForwardRange[H],
) ForwardRange[Octet[A, B, C, D, E, F, G, H]]

Zip8F produces items from 8 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip9F

func Zip9F[A, B, C, D, E, F, G, H, I any](
	a ForwardRange[A],
	b ForwardRange[B],
	c ForwardRange[C],
	d ForwardRange[D],
	e ForwardRange[E],
	f ForwardRange[F],
	g ForwardRange[G],
	h ForwardRange[H],
	i ForwardRange[I],
) ForwardRange[Ennead[A, B, C, D, E, F, G, H, I]]

Zip9F produces items from 9 ranges in parallel. The range will be empty when any of the ranges are empty.

func ZipNF

func ZipNF(ranges ...ForwardRange[any]) ForwardRange[[]any]

ZipNF is `ZipN` that allows the range to be saved.

type HasLength deprecated

type HasLength interface {
	Length() int
}

HasLength is any type that has a length.

Deprecated: This was unused in the library, and doesn't map well to Go programming.

Length ought to be a constant-time access operation.

type InputRange

type InputRange[T any] interface {
	Empty() bool
	Front() T
	PopFront()
}

InputRange is any type you can read sequentially.

func Cache

func Cache[T any](r InputRange[T]) InputRange[T]

Cache eagerly caches the first element in a range and caches values so `Front()` is only called once per element for the original range.

func Chain

func Chain[T any](ranges ...InputRange[T]) InputRange[T]

Chain produces the results of all the ranges together in a sequence.

func ChunkBy

func ChunkBy[T any](r InputRange[T], cb func(a, b T) bool) InputRange[InputRange[T]]

Returns a range that splits a range into subranges when `cb(a, b)` returns `false`.

func ChunkByValue

func ChunkByValue[T any, U comparable](r InputRange[T], cb func(a T) U) InputRange[InputRange[T]]

Returns `ChunkBy` with `cb(a) == cb(b)`

func Chunks

func Chunks[T any](r InputRange[T], size int) InputRange[InputRange[T]]

Chunks returns sub-ranges that are at most `size` in length.

func Drop

func Drop[T any](r InputRange[T], count int) InputRange[T]

Drop creates a range without the first up to `count` elements

func DropWhile

func DropWhile[T any](r InputRange[T], cb func(element T) bool) InputRange[T]

DropWhile advances a range while cb(element) returns `true`

func Enumerate

func Enumerate[T any](r InputRange[T]) InputRange[Pair[int, T]]

Enumerate yields elements with indexes starting from 0

func EnumerateN

func EnumerateN[T any](r InputRange[T], n int) InputRange[Pair[int, T]]

EnumerateN yields elements with indexes starting from n

func Filter

func Filter[T any](r InputRange[T], cb func(element T) bool) InputRange[T]

Filter filters down to elements where `cb(element)` returns `true`

func Find

func Find[T any](haystack InputRange[T], cb func(a, b T) bool, needle T) InputRange[T]

Find advances a range until cb(a, b) returns `true`, comparing with needle.

func FindAmong

func FindAmong[T any](haystack InputRange[T], cb func(a, b T) bool, needle ForwardRange[T]) InputRange[T]

FindAmong advances until `cb(a, b) == true` for any element of `needle`.

func FindAmongComparable

func FindAmongComparable[T comparable](haystack InputRange[T], needle ForwardRange[T]) InputRange[T]

FindAmongComparable advances until `a == b` for any element of `needle`.

func FindComparable

func FindComparable[T comparable](haystack InputRange[T], needle T) InputRange[T]

FindComparable advances a range until Front() == needle

func Flatten

func Flatten[T any](r InputRange[InputRange[T]]) InputRange[T]

Flatten combines a range of ranges into one straight range

func FrontTransversal

func FrontTransversal[T any](r InputRange[InputRange[T]]) InputRange[T]

FrontTransversal yields the first value in each range, skipping empty ranges.

func Group

func Group[T any](r InputRange[T], cb func(a, b T) bool) InputRange[Pair[T, int]]

Group yields pairs of (value, size) from a range where values are equal according to `cb(a, b)`

func GroupComparable

func GroupComparable[T comparable](r InputRange[T]) InputRange[Pair[T, int]]

GroupComparable is `Group` where `a == b`

func GroupComparableS

func GroupComparableS[T comparable](r []T) InputRange[Pair[T, int]]

GroupComparableS is `GroupComparable` accepting a slice.

func GroupS

func GroupS[T any](r []T, cb func(a, b T) bool) InputRange[Pair[T, int]]

GroupS is `Group` accepting a slice.

func I

func I[T any](r ForwardRange[T]) InputRange[T]

I is a convenience function for passing a ForwardRange as an InputRange.

func Joiner

func Joiner[T any](r InputRange[InputRange[T]], separator ForwardRange[T]) InputRange[T]

Joiner joins ranges together using a given ForwardRange as a separator.

func Map

func Map[T any, U any](r InputRange[T], cb func(a T) U) InputRange[U]

Map transforms elements from one to another through `cb(element)`

`cb` will be called each time `Front()` is called.

The `Cache` function can be used to cache the result when generating ranges.

func Mismatch10

func Mismatch10[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
	f InputRange[T],
	g InputRange[T],
	h InputRange[T],
	i InputRange[T],
	j InputRange[T],
) InputRange[Decade[T, T, T, T, T, T, T, T, T, T]]

Mismatch10 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch2

func Mismatch2[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
) InputRange[Pair[T, T]]

Mismatch2 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch3

func Mismatch3[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
) InputRange[Triplet[T, T, T]]

Mismatch3 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch4

func Mismatch4[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
) InputRange[Quartet[T, T, T, T]]

Mismatch4 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch5

func Mismatch5[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
) InputRange[Quintet[T, T, T, T, T]]

Mismatch5 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch6

func Mismatch6[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
	f InputRange[T],
) InputRange[Sextet[T, T, T, T, T, T]]

Mismatch6 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch7

func Mismatch7[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
	f InputRange[T],
	g InputRange[T],
) InputRange[Septet[T, T, T, T, T, T, T]]

Mismatch7 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch8

func Mismatch8[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
	f InputRange[T],
	g InputRange[T],
	h InputRange[T],
) InputRange[Octet[T, T, T, T, T, T, T, T]]

Mismatch8 eagerly advances all ranges in lockstep until `eq` returns `false`.

func Mismatch9

func Mismatch9[T any](
	eq func(a, b T) bool,
	a InputRange[T],
	b InputRange[T],
	c InputRange[T],
	d InputRange[T],
	e InputRange[T],
	f InputRange[T],
	g InputRange[T],
	h InputRange[T],
	i InputRange[T],
) InputRange[Ennead[T, T, T, T, T, T, T, T, T]]

Mismatch9 eagerly advances all ranges in lockstep until `eq` returns `false`.

func PadRight

func PadRight[T any](r InputRange[T], value T, count int) InputRange[T]

PadRight adds up to `count` `value` elements to the end of a range to ensure it's at least `count` elements long.

func RoundRobin

func RoundRobin[T any](ranges ...InputRange[T]) InputRange[T]

RoundRobin yields the first elements of the ranges and cycles back around until all are consumed.

func SplitWhen

func SplitWhen[T any](r InputRange[T], cb func(a, b T) bool) InputRange[InputRange[T]]

SplitWhen splits a range where `cb(a, b) == true` for adjacent elements.

func Stride

func Stride[T any](r InputRange[T], step int) InputRange[T]

Stride produces every `step` elements in a range.

func StripLeft

func StripLeft[T any](r InputRange[T], cb func(a T) bool) InputRange[T]

StripLeft removes elements where `cb(a) == true` from the front of a range.

func StripLeftComparable

func StripLeftComparable[T comparable](r InputRange[T], value T) InputRange[T]

StripLeftComparable removes elements equal to `value` from the front of a range.

func Take

func Take[T any](r InputRange[T], count int) InputRange[T]

Take creates a range of up to `count` elements from the start of a range.

func TakeWhile

func TakeWhile[T any](r InputRange[T], cb func(element T) bool) InputRange[T]

TakeWhile advances a range while `cb` returns `true`

func Tee

func Tee[T any](r InputRange[T], output OutputRange[T]) InputRange[T]

Tee produces a range that outputs to a given 'output' when elements are popped.

func TeeS

func TeeS[T any](r []T, output OutputRange[T]) InputRange[T]

TeeS is `Tee` accepting a slice.

func Uniq

func Uniq[T any](r InputRange[T], cb func(a, b T) bool) InputRange[T]

Uniq removes adjacent entries where `cb(a, b) == true`

func UniqComparable

func UniqComparable[T comparable](r InputRange[T]) InputRange[T]

UniqComparable removes adjacent entries where `a == b`

func Zip10

func Zip10[A, B, C, D, E, F, G, H, I, J any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
	f InputRange[F],
	g InputRange[G],
	h InputRange[H],
	i InputRange[I],
	j InputRange[J],
) InputRange[Decade[A, B, C, D, E, F, G, H, I, J]]

Zip10 produces items from 10 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip2

func Zip2[A, B any](
	a InputRange[A],
	b InputRange[B],
) InputRange[Pair[A, B]]

Zip2 produces items from 2 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip3

func Zip3[A, B, C any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
) InputRange[Triplet[A, B, C]]

Zip3 produces items from 3 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip4

func Zip4[A, B, C, D any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
) InputRange[Quartet[A, B, C, D]]

Zip4 produces items from 4 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip5

func Zip5[A, B, C, D, E any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
) InputRange[Quintet[A, B, C, D, E]]

Zip5 produces items from 5 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip6

func Zip6[A, B, C, D, E, F any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
	f InputRange[F],
) InputRange[Sextet[A, B, C, D, E, F]]

Zip6 produces items from 6 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip7

func Zip7[A, B, C, D, E, F, G any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
	f InputRange[F],
	g InputRange[G],
) InputRange[Septet[A, B, C, D, E, F, G]]

Zip7 produces items from 7 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip8

func Zip8[A, B, C, D, E, F, G, H any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
	f InputRange[F],
	g InputRange[G],
	h InputRange[H],
) InputRange[Octet[A, B, C, D, E, F, G, H]]

Zip8 produces items from 8 ranges in parallel. The range will be empty when any of the ranges are empty.

func Zip9

func Zip9[A, B, C, D, E, F, G, H, I any](
	a InputRange[A],
	b InputRange[B],
	c InputRange[C],
	d InputRange[D],
	e InputRange[E],
	f InputRange[F],
	g InputRange[G],
	h InputRange[H],
	i InputRange[I],
) InputRange[Ennead[A, B, C, D, E, F, G, H, I]]

Zip9 produces items from 9 ranges in parallel. The range will be empty when any of the ranges are empty.

func ZipN

func ZipN(ranges ...InputRange[any]) InputRange[[]any]

ZipN produces items from any n ranges in parallel.

type Integer

type Integer interface {
	Signed | Unsigned
}

Integer integer type.

type Octet

type Octet[A, B, C, D, E, F, G, H any] struct {
	A A
	B B
	C C
	D D
	E E
	F F
	G G
	H H
}

Octet holds 8 items

func MakeOctet

func MakeOctet[A, B, C, D, E, F, G, H any](a A, b B, c C, d D, e E, f F, g G, h H) Octet[A, B, C, D, E, F, G, H]

MakeOctet creates a Octet

func (Octet[A, B, C, D, E, F, G, H]) Get added in v0.3.0

func (o Octet[A, B, C, D, E, F, G, H]) Get() (A, B, C, D, E, F, G, H)

Get returns items as a Go tuple

type Ordered

type Ordered interface {
	RealNumber | ~string
}

Ordered is any type can can be compared with < and >

type OutputRange

type OutputRange[T any] interface {
	Put(element T) error
}

OutputRange is any type that values can be output to.

func AssignSink

func AssignSink[T any](r InputRange[*T]) OutputRange[T]

AssignSink assigns values by derefencing pointers from a range.

func NullSink

func NullSink[T any]() OutputRange[T]

NullSink returns a sink that discards output.

func SliceSink

func SliceSink[T any](slice *[]T) OutputRange[T]

SliceSink creates a OutputRange that appends elements to the slice.

type Pair

type Pair[A, B any] struct {
	A A
	B B
}

Pair holds 2 items

func MakePair

func MakePair[A, B any](a A, b B) Pair[A, B]

MakePair creates a Pair

func (Pair[A, B]) Get added in v0.3.0

func (p Pair[A, B]) Get() (A, B)

Get returns items as a Go tuple

type Quartet

type Quartet[A, B, C, D any] struct {
	A A
	B B
	C C
	D D
}

Quartet holds 4 items

func MakeQuartet

func MakeQuartet[A, B, C, D any](a A, b B, c C, d D) Quartet[A, B, C, D]

MakeQuartet creates a Quartet

func (Quartet[A, B, C, D]) Get added in v0.3.0

func (q Quartet[A, B, C, D]) Get() (A, B, C, D)

Get returns items as a Go tuple

type Quintet

type Quintet[A, B, C, D, E any] struct {
	A A
	B B
	C C
	D D
	E E
}

Quintet holds 5 items

func MakeQuintet

func MakeQuintet[A, B, C, D, E any](a A, b B, c C, d D, e E) Quintet[A, B, C, D, E]

MakeQuintet creates a Quintet

func (Quintet[A, B, C, D, E]) Get added in v0.3.0

func (q Quintet[A, B, C, D, E]) Get() (A, B, C, D, E)

Get returns items as a Go tuple

type RandomAccessRange added in v0.4.0

type RandomAccessRange[T any] interface {
	BidirectionalRange[T]
	Get(index int) T
	Len() int
	SaveR() RandomAccessRange[T]
}

RandomAccessRange is a Bidirectional ranges with a known length.

Len() ought to be a constant-time access operation, as in O(1)

func Bytes

func Bytes(s string) RandomAccessRange[byte]

Bytes produces a range over the bytes of string.

func DropR added in v0.4.0

func DropR[T any](r RandomAccessRange[T], count int) RandomAccessRange[T]

DropR is `DropB` permitting random access.

func MapR added in v0.4.0

func MapR[T any, U any](r RandomAccessRange[T], cb func(a T) U) RandomAccessRange[U]

MapR is `MapB` with random access.

`cb` will be called each time `Get()` is called.

func MapS

func MapS[T any, U any](r []T, cb func(a T) U) RandomAccessRange[U]

MapS is `MapR` accepting a slice.

func Null

func Null[T any]() RandomAccessRange[T]

Returns a range that's empty

func Only

func Only[T any](values ...T) RandomAccessRange[T]

Only returns a ForwardRange through the arguments provided.

func RetroR added in v0.4.0

func RetroR[T any](r RandomAccessRange[T]) RandomAccessRange[T]

RetroR is Retro, producing a RandomAccessRange.

func Runes

func Runes(s string) RandomAccessRange[rune]

Runes produces a range over the runes of string.

func SlicePtrRange

func SlicePtrRange[T any](slice []T) RandomAccessRange[*T]

SlicePtrRange creates a range of pointers to values from a slice.

func SlicePtrRetroRange

func SlicePtrRetroRange[T any](slice []T) RandomAccessRange[*T]

SlicePtrRetroRange creates a range of pointers to values from a slice in reverse.

func SliceRange

func SliceRange[T any](slice []T) RandomAccessRange[T]

SliceRange creates a range from a slice.

func SliceRetroRange

func SliceRetroRange[T any](slice []T) RandomAccessRange[T]

SliceRetroRange creates a range from a slice in reverse.

func StripComparableR added in v0.4.0

func StripComparableR[T comparable](r RandomAccessRange[T], value T) RandomAccessRange[T]

StripComparableR is `StripComparable` with random access.

func StripComparableS

func StripComparableS[T comparable](r []T, value T) RandomAccessRange[T]

StripComparableS is `StripComparable` accepting a slice.

func StripLeftComparableR added in v0.4.0

func StripLeftComparableR[T comparable](r RandomAccessRange[T], value T) RandomAccessRange[T]

StripLeftComparableR is `StripLeftComparableB` with random access.

func StripLeftComparableS

func StripLeftComparableS[T comparable](r []T, value T) RandomAccessRange[T]

StripLeftComparableS is `StripLeftComparableR` accepting a slice.

func StripLeftR added in v0.4.0

func StripLeftR[T any](r RandomAccessRange[T], cb func(a T) bool) RandomAccessRange[T]

StripLeftR is `StripLeftB` with random access.

func StripLeftS

func StripLeftS[T any](r []T, cb func(a T) bool) RandomAccessRange[T]

StripLeftS is `StripLeftR` accepting a slice.

func StripR added in v0.4.0

func StripR[T any](r RandomAccessRange[T], cb func(a T) bool) RandomAccessRange[T]

StripR is `Strip` with random access.

func StripRightComparableR added in v0.4.0

func StripRightComparableR[T comparable](r RandomAccessRange[T], value T) RandomAccessRange[T]

StripRightComparableR is `StripRightComparable` with random access.

func StripRightComparableS

func StripRightComparableS[T comparable](r []T, value T) RandomAccessRange[T]

StripRightComparableS is `StripRightComparableF` accepting a slice.

func StripRightR added in v0.4.0

func StripRightR[T any](r RandomAccessRange[T], cb func(a T) bool) RandomAccessRange[T]

StripRightR is `StripRight` with random access.

func StripRightS

func StripRightS[T any](r []T, cb func(a T) bool) RandomAccessRange[T]

StripRightS is `StripRightR` accepting a slice.

func StripS

func StripS[T any](r []T, cb func(a T) bool) RandomAccessRange[T]

StripS is `StripR` accepting a slice.

type RealNumber

type RealNumber interface {
	Integer | Float
}

Any basic real number type

type Septet

type Septet[A, B, C, D, E, F, G any] struct {
	A A
	B B
	C C
	D D
	E E
	F F
	G G
}

Septet holds 7 items

func MakeSeptet

func MakeSeptet[A, B, C, D, E, F, G any](a A, b B, c C, d D, e E, f F, g G) Septet[A, B, C, D, E, F, G]

MakeSeptet creates a Septet

func (Septet[A, B, C, D, E, F, G]) Get added in v0.3.0

func (s Septet[A, B, C, D, E, F, G]) Get() (A, B, C, D, E, F, G)

Get returns items as a Go tuple

type Sextet

type Sextet[A, B, C, D, E, F any] struct {
	A A
	B B
	C C
	D D
	E E
	F F
}

Sextet holds 6 items

func MakeSextet

func MakeSextet[A, B, C, D, E, F any](a A, b B, c C, d D, e E, f F) Sextet[A, B, C, D, E, F]

MakeSextet creates a Sextet

func (Sextet[A, B, C, D, E, F]) Get added in v0.3.0

func (s Sextet[A, B, C, D, E, F]) Get() (A, B, C, D, E, F)

Get returns items as a Go tuple

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed is any signed integer type.

type Triplet

type Triplet[A, B, C any] struct {
	A A
	B B
	C C
}

Triplet holds 3 items

func MakeTriplet

func MakeTriplet[A, B, C any](a A, b B, c C) Triplet[A, B, C]

MakeTriplet creates a Triplet

func (Triplet[A, B, C]) Get added in v0.3.0

func (t Triplet[A, B, C]) Get() (A, B, C)

Get returns items as a Go tuple

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is any unsigned integer type.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy