iter

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Utility iterator functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromSlice

func FromSlice[T any](s []T) c.Iterator[T]

func Map

func Map[I any, O any](it c.Iterator[I], to func(item I) O) c.Iterator[O]

Map will map values of type `I` from to type `O` through the `to` mapper function.

Example:

v := collection.Vec[int]{1, 2, 3, 4, 5, 6, 7, 8, 9}
number_iterator := v.Iter().Filter(func(item int) string { return item%2 == 0})
iter.Map(number_iterator, func(item int) string { return fmt.Sprint("number ", item) }).
	ForEach(func(item string) { fmt.Prinln(item) })

This is a workaround to implement `Map` as currently methods cannot have type paramters.

func Range

func Range(end int) c.Iterator[int]

Iterate from 0 to `end` by steps of 1

func Reduce

func Reduce[I any, O any](it c.Iterator[I], start O, reducer func(acc O, item I) O) O

Reduce will reduce the values through the reducer

This is a workaround to implement `Reduce` as currently methods cannot have type paramters.

func Sum

func Sum[T constraints.Ordered](it c.Iterator[T]) T

Sum will return the sum of the values. If the iterated values are strings it will concatenate them

func XRange

func XRange(start, end, step int) c.Iterator[int]

Iterate from `start` to `end` by steps of `step`. Currently the range will only increase, the step will be added for each iteration so make sure that it will eventually reach the end, otherwise you enter an infinite loop.

Types

This section is empty.

Jump to

Keyboard shortcuts

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