Documentation ¶
Overview ¶
Package transform contains transformation utilities that work on sequences represented by iterator functions.
They implement patterns commonly used with iterators returned by Limestone's snapshot.Search and snapshot.All methods. However, this library isn't tied to Limestone.
Index ¶
- func Collect(iter Iterator, ptrSlice any) int
- func Count(iter Iterator) int
- func ForEach(iter Iterator, fn any) int
- func GetUnique(iter Iterator, ptr any) bool
- func IsEmpty(iter Iterator) bool
- func IsShorter(iter Iterator, length int) bool
- func MustGetUnique(iter Iterator, ptr any)
- func Null(ptr any) bool
- type Iterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect appends all items from the sequence to a slice to which ptrSlice points. Returns the number of items collected.
func ForEach ¶
ForEach calls fn for every item of the sequence. The function must take a sequence item by value and return either bool or nothing. If it returns bool, it can break out of the iteration by returning false.
Returns the number of times fn was called.
func GetUnique ¶
GetUnique returns true if the sequence has one item, and copies that item to the memory at ptr. Returns false if the sequence is empty. Panics if the sequence has more than one item.
func MustGetUnique ¶
MustGetUnique retrieves the only item from the sequence and copies it to the memory at ptr. Panics unless the sequence has exactly one item.
Types ¶
type Iterator ¶
Iterator is an iterator over a sequence. Every call fills in another object into ptr argument. Returns false when the end of dataset is reached (the data at ptr won't be modified in this call).
Iterator must accept nil instead of a pointer. When the argument is nil, the iterator must discard one item. The calling code can use this to skip sequence items.
func Concatenate ¶
Concatenate returns a sequence made by concatenating all the given sequences
func Filter ¶
Filter returns an iterator for the sequence made of only those items of the original sequence for which predicate returns true. The predicate must be a function taking a sequence item by value and returning bool.
func Map ¶
Map returns a new sequence made by applying the given function to each item. The function must accept an item by value and return an item. The output item may be of a different type. The mapping function can optionally accept a second argument of type int. It will receive the 0-based index of the current item within the sequence.