transform

package
v0.0.0-...-406b1e7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect(iter Iterator, ptrSlice any) int

Collect appends all items from the sequence to a slice to which ptrSlice points. Returns the number of items collected.

func Count

func Count(iter Iterator) int

Count returns the length of a sequence

func ForEach

func ForEach(iter Iterator, fn any) int

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

func GetUnique(iter Iterator, ptr any) bool

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 IsEmpty

func IsEmpty(iter Iterator) bool

IsEmpty returns true if the sequence is empty

func IsShorter

func IsShorter(iter Iterator, length int) bool

IsShorter returns whether the length of the sequence is less than a given number

func MustGetUnique

func MustGetUnique(iter Iterator, ptr any)

MustGetUnique retrieves the only item from the sequence and copies it to the memory at ptr. Panics unless the sequence has exactly one item.

func Null

func Null(ptr any) bool

Null is an iterator over an empty sequence

Types

type Iterator

type Iterator = func(ptr any) bool

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

func Concatenate(iter ...Iterator) Iterator

Concatenate returns a sequence made by concatenating all the given sequences

func Filter

func Filter(iter Iterator, predicate any) Iterator

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 FromSlice

func FromSlice(slice any) Iterator

FromSlice returns an iterator over a slice

func Limit

func Limit(iter Iterator, max int) Iterator

Limit truncates the sequence if it's longer than max items

func Map

func Map(iter Iterator, mapping any) Iterator

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.

Jump to

Keyboard shortcuts

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