Documentation ¶
Index ¶
- func Append[T any](vs []T, v T) []T
- func Filter[T any, R Adder[T]](values Iterator[T], p Predicate[T], result R) R
- func FilterIntoSlice[T any](values Iterator[T], p Predicate[T]) []T
- func Map[T any, U any, R Adder[U]](values Iterator[T], transform func(T) U, result R) R
- func MapIntoSlice[T any, U any](values Iterator[T], transform func(T) U) []U
- func Reduce[T any, R any](values Iterator[T], initial R, f func(R, T) R) R
- type Adder
- type AddingEntry
- type BasicSeq
- type Entries
- type Entry
- type FixedFunction
- type Func1
- type Func2
- type Func3
- type FuncN
- type Iterable
- type Iterator
- type Keys
- type Predicate
- type Predicate2
- type Predicate3
- type Proc1
- type Proc2
- type Proc3
- type Seq
- type Seqable
- type Set
- type Slice
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[T any](vs []T, v T) []T
Append wraps the built in append, so that you can pass it around as a function object
func Filter ¶
Filter takes an iterator of values and a predicate function and a result which can be added into. It will go through all values, and add the elements for which the predicate returns true to the result.
func FilterIntoSlice ¶
FilterIntoSlice uses Filter to add every element from the iterator where the predicate returns true to a slice, and return that slice.
func Map ¶
Map will turn the values in the given iterator into values of another type, using the transform function, and then adding these resulting values to the given Adder, and returning it.
func MapIntoSlice ¶
MapIntoSlice transforms the values given in the iterator using the transform function and returns a slice of these resulting values.
func Reduce ¶
Reduce will iterate over the values in the iterator and chain the values together with the previous value generated by the function. The initial parameter will be the start of this chain, and the result of the last call will be the result of the Reduce function call. This function is sometimes known as Fold or Inject instead of Reduce.
Types ¶
type Adder ¶
type Adder[T any] interface { // Add will take a value of the generic type T and add it to the underlying container. Add(T) }
Adder is an interface that corresponds to a type that can mutably add an item to its underlying type. This type is used in places such as `Map` and `Reduce` in order to generically inject result data into arbitrary containers.
type AddingEntry ¶
type AddingEntry[K comparable, V any] map[K]V
AddingEntry is a wrapper type that allows you to use a map in a setting where you want a sequence or collection operation to add entries to a map, for example using Filter or Reduce.
func (AddingEntry[K, V]) Add ¶
func (m AddingEntry[K, V]) Add(e Entry[K, V])
Add will add the key with the specified value to the underlying map
type BasicSeq ¶
type BasicSeq[T any] interface { // Next returns the next possible element from the sequence. If the sequence has // reached its end, it will return the zero value for the generic type T. // Every call to Next will move the sequence forward one step. Next() T // HasNext returns true if there are more elements in the sequence, and false otherwise. // It is safe to call HasNext multiple times without calling Next inbetween. HasNext() bool }
BasicSeq is the smallest possible lazy sequence interface. It allows you to pull the next element from the sequence, and check if there are more elements left in the sequence. BasicSeq is not defined to be concurrency safe and no implementation of it can be relied on to be concurrency safe, unless otherwise stated for that implementation.
type Entries ¶
type Entries[K comparable, V any] map[K]V
Entries allow you to wrap a map and iterate or sequence over the key-value pairs in it
type Entry ¶
type Entry[K comparable, V any] struct { // Key is the key for the Entry Key K // Value is the value that the specific key maps to Value V }
Entry is a data structure that can be used to understand pieces of a dictionary/map data structure. Each Entry will have its own key and value of given types.
type FixedFunction ¶
type FixedFunction[R any] func() R
FixedFunction is a function that doesn't take any arguments and returns one result
type Func1 ¶
type Func1[A, R any] func(A) R
Func1 is a function of one argument to one result
func Compose ¶
Compose allows you to chain methods making the order of application slightly cleaner. The idea is that instead of doing f2(f1(arg)) you can do Compose(f1, f2)(arg). This is similar to the . operator in Haskell, for example.
func (Func1[A, R]) Partial ¶
func (f Func1[A, R]) Partial(v A) FixedFunction[R]
Partial allows you to partially apply the function, returning a new function with one less argument than the function previously took. The return function will always receive the fixed value as it's return
type Func2 ¶
type Func2[A1, A2, R any] func(A1, A2) R
Func2 is a function of two arguments to one result
func (Func2[A1, A2, R]) Partial ¶
Partial allows you to partially apply the function, returning a new function with one less argument than the function previously took. The return function will always receive the fixed value as it's return. For example, imagine you have: ```func add(left, right int) int { return left + right }``` You can partially apply it: ```add42 := Func2(add).Partial(42)``` and then use it as a unary function: ```add42(5) // => 47```
type Func3 ¶
type Func3[A1, A2, A3, R any] func(A1, A2, A3) R
Func3 is a function of three arguments to one result
type FuncN ¶
type FuncN[A, R any] func(...A) R
FuncN is a function of a variable number of arguments to one result
type Iterable ¶
type Iterable[T any] interface { // Iter returns an Iterator for the type of the collection Iter() Iterator[T] }
Iterable represents an object that can create an iterator
type Iterator ¶
type Iterator[T any] interface { // Each will call the given procedure once for every element in the collection, // giving the element as an argument to the procedure. Each(Proc1[T]) }
Iterator represents an object that has the capacity to visit each elements. THis interface does not guarantee an ordered visit - only that each element will be visited once.
type Keys ¶
type Keys[K comparable, V any] map[K]V
Keys allow you to wrap a map and use the keys in the map as an Iterator or Seq.
func (Keys[K, V]) Adder ¶
Adder takes a fixed value and returns an implementation of Adder that will add new keys to the underlying map with the same fixed value.
func (Keys[K, V]) Each ¶
Each will visit each key in the underlying map and yield the key to the procedure. The order of iteration is not defined.
type Predicate ¶
Predicate is a function that takes one argument and returns true or false
func (Predicate[A]) And ¶
And will return a new Predicate that is only true if both given Predicates return true for the argument given
func (Predicate[A]) Not ¶
Not returns a new Predicate that gives the inverse response for the given argument that the original predicate would have given.
type Predicate2 ¶
Predicate2 is a function that takes two arguments and returns true or false
func (Predicate2[A1, A2]) And ¶
func (p Predicate2[A1, A2]) And(p2 Predicate2[A1, A2]) Predicate2[A1, A2]
And will return a new Predicate that is only true if both given Predicates return true for the arguments given
func (Predicate2[A1, A2]) Not ¶
func (p Predicate2[A1, A2]) Not() Predicate2[A1, A2]
Not returns a new Predicate that gives the inverse response for the given arguments that the original predicate would have given.
func (Predicate2[A1, A2]) Or ¶
func (p Predicate2[A1, A2]) Or(p2 Predicate2[A1, A2]) Predicate2[A1, A2]
Or will return a new Predicate that is only true if at least one of the given Predicates return true for the arguments given
func (Predicate2[A1, A2]) Xor ¶
func (p Predicate2[A1, A2]) Xor(p2 Predicate2[A1, A2]) Predicate2[A1, A2]
Xor will return a new Predicate that is only true if exactly one of the given Predicates return true for the arguments given
type Predicate3 ¶
Predicate3 is a function that takes three arguments and returns true or false
type Proc1 ¶
type Proc1[A any] func(A)
Proc1 is a procedure that takes one argument and doesn't return any result
type Proc2 ¶
type Proc2[A1, A2 any] func(A1, A2)
Proc2 is a procedure that takes two arguments and doesn't return any result
type Proc3 ¶
type Proc3[A1, A2, A3 any] func(A1, A2, A3)
Proc3 is a procedure that takes three arguments and doesn't return any result
type Seq ¶
type Seq[T any] interface { Iterator[T] BasicSeq[T] // Into will evaluate the full sequence and add it into the given adder Into(Adder[T]) // IntoSlice will evaluate the full sequence and generate a slice of the result IntoSlice() []T // Filter will take the given predicate and return a new lazy sequence that // only yields values for which the predicate returns true. Filter(Predicate[T]) Seq[T] }
Seq represents a lazy sequence that can also do some basic filtering and generating operations
func FullSeqFrom ¶
FullSeqFrom takes a BasicSeq and returns a full Seq implementation using only the methods defined in BasicSeq
type Seqable ¶
Seqable represents a type that can be lazily iterated over by generating a Seq from it
type Set ¶
type Set[T comparable] interface { Iterable[T] Iterator[T] // Add will add the given element to the set. If the element already is in the set, // this method doesn't do anything. Add(T) // AddAll adds all the given arguments to the set, using the same logic as Add AddAll(...T) // Intersection returns a new Set that represents the intersection between this // set and the argument Intersection(Set[T]) Set[T] // Union returns a new Set that represents the union of this set and the argument Union(Set[T]) Set[T] // Difference returns a new Set containing only the elements from the receiver that // are not in the argument set Difference(Set[T]) Set[T] // SubSetOf returns true if the receiver Set is a sub set of the argument set SubSetOf(Set[T]) bool // Equal returns true if the receiver contains the same elements as the argument set Equal(Set[T]) bool // Contains returns true if the given argument is in the set Contains(T) bool // Size returns the number of elements in the set Size() int // Empty returns true if this is the empty set Empty() bool // ToSlice will return a slice with each element, in an undefined order ToSlice() []T }
Set represents an unordered collection of objects. Sets can be compared for equality, and the elements manipulated in the expected ways
func SetFrom ¶
func SetFrom[T comparable](values ...T) Set[T]
SetFrom will create a set containing the given values
type Slice ¶
type Slice[T any] []T
Slice wraps a slice so that you can iterate or sequence over it
type Values ¶
type Values[K comparable, V any] map[K]V
Values allow you to wrap a map and iterate or sequence over the values in it
func (Values[K, V]) Each ¶
Each will visit each value in the map and yield it to the given function If the map contains the same value more than once, the function will receive it once for every time it is available in the map