Type manipulation - Iterator helpers
This page lists all type operations available in the it lo sub-package.
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
Emptyโ
Returns an empty sequence of the specified type.
Examples:
emptySeq := it.Empty[int]()count := 0for range emptySeq {count++}// count == 0emptySeq := it.Empty[string]()var result []stringfor v := range emptySeq {result = append(result, v)}// result is empty sliceSimilar:Prototype:func Empty[T any]() iter.Seq[T]IsEmptyโ
Returns true if the sequence is empty. Will consume the entire sequence to check.
Examples:
seq := func(yield func(int) bool) {// empty sequence}empty := it.IsEmpty(seq)// empty == trueseq := func(yield func(int) bool) {_ = yield(1)_ = yield(2)}empty := it.IsEmpty(seq)// empty == falseSimilar:Prototype:func IsEmpty[T any](collection iter.Seq[T]) boolCoalesceSeqโ
Returns the first non-empty sequence from the provided arguments, with a boolean indicating if a non-empty sequence was found.
emptySeq := func(yield func(int) bool) bool {return false // empty sequence}nonEmptySeq := it.Range(3)result, ok := it.CoalesceSeq(emptySeq, nonEmptySeq, emptySeq)// iter.Seq[int] yielding 0, 1, 2, trueemptyStrSeq := func(yield func(string) bool) bool {return false // empty sequence}strSeq := func(yield func(string) bool) bool {yield("a")yield("b")return true}result, ok = it.CoalesceSeq(emptyStrSeq, strSeq)// iter.Seq[string] yielding "a", "b", trueresult, ok = it.CoalesceSeq(emptySeq, emptyStrSeq)// nil sequence, falsePrototype:func CoalesceSeq[T any](v ...iter.Seq[T]) (iter.Seq[T], bool)CoalesceSeqOrEmptyโ
Returns the first non-empty sequence from the provided arguments, or an empty sequence if all arguments are empty.
emptySeq := func(yield func(int) bool) bool {return false // empty sequence}nonEmptySeq := it.Range(3)result := it.CoalesceSeqOrEmpty(emptySeq, nonEmptySeq, emptySeq)// iter.Seq[int] yielding 0, 1, 2emptyStrSeq := func(yield func(string) bool) bool {return false // empty sequence}strSeq := func(yield func(string) bool) bool {yield("a")yield("b")return true}result = it.CoalesceSeqOrEmpty(emptyStrSeq, strSeq)// iter.Seq[string] yielding "a", "b"result = it.CoalesceSeqOrEmpty(emptySeq, emptyStrSeq)// empty sequence (yields nothing)Prototype:func CoalesceSeqOrEmpty[T any](v ...iter.Seq[T]) iter.Seq[T]ToSeqPtrโ
ToSeqPtr returns a sequence of pointers to each value.
collection := func(yield func(int) bool) {yield(1)yield(2)yield(3)}ptrs := it.ToSeqPtr(collection)var result []*intfor ptr := range ptrs {result = append(result, ptr)}// result contains pointers to 1, 2, 3Similar:Prototype:func ToSeqPtr[T any](collection iter.Seq[T]) iter.Seq[*T]FromSeqPtrโ
FromSeqPtr returns a sequence with the pointer values.
Returns a zero value in case of a nil pointer element.one := 1two := 2var three *int = nilcollection := func(yield func(*int) bool) {yield(&one)yield(&two)yield(three)}values := it.FromSeqPtr(collection)var result []intfor val := range values {result = append(result, val)}// result contains [1, 2, 0]Variant:Similar:Prototype:func FromSeqPtr[T any](collection iter.Seq[*T]) iter.Seq[T]FromSeqPtrOrโ
FromSeqPtrOr returns a sequence with the pointer values or the fallback value.
one := 1var two *int = nilcollection := func(yield func(*int) bool) {yield(&one)yield(two)}values := it.FromSeqPtrOr(collection, 99)var result []intfor val := range values {result = append(result, val)}// result contains [1, 99]Variant:Prototype:func FromSeqPtrOr[T any](collection iter.Seq[*T], fallback T) iter.Seq[T]ToAnySeqโ
ToAnySeq returns a sequence with all elements mapped to
anytype.collection := func(yield func(int) bool) {yield(1)yield(2)yield(3)}anySeq := it.ToAnySeq(collection)var result []anyfor item := range anySeq {result = append(result, item)}// result contains [1, 2, 3] as any typeVariant:Similar:Prototype:func ToAnySeq[T any](collection iter.Seq[T]) iter.Seq[any]FromAnySeqโ
FromAnySeq returns a sequence with all elements mapped to a type.
Panics on type conversion failure.collection := func(yield func(any) bool) {yield(1)yield(2)yield("three") // This will cause panic}intSeq := it.FromAnySeq[int](collection)// This will panic when trying to convert "three" to intVariant:Similar:Prototype:func FromAnySeq[T any](collection iter.Seq[any]) iter.Seq[T]Emptyโ
Empty returns an empty sequence.
empty := it.Empty[int]()var result []intfor item := range empty {result = append(result, item)}// result is empty []IsEmpty returns true if the sequence is empty.
emptySeq := it.Empty[int]()notEmptySeq := func(yield func(int) bool) {yield(1)}fmt.Println(it.IsEmpty(emptySeq)) // truefmt.Println(it.IsEmpty(notEmptySeq)) // falseIsNotEmpty returns true if the sequence is not empty.
emptySeq := it.Empty[int]()notEmptySeq := func(yield func(int) bool) {yield(1)}fmt.Println(it.IsNotEmpty(emptySeq)) // falsefmt.Println(it.IsNotEmpty(notEmptySeq)) // trueCoalesceSeq returns the first non-empty sequence.
empty1 := it.Empty[int]()empty2 := it.Empty[int]()notEmpty := func(yield func(int) bool) {yield(1)yield(2)}result, found := it.CoalesceSeq(empty1, empty2, notEmpty)// found is true, result is the notEmpty sequenceresult2, found2 := it.CoalesceSeq(empty1, empty2)// found2 is false, result2 is an empty sequenceCoalesceSeqOrEmpty returns the first non-empty sequence.
empty1 := it.Empty[int]()empty2 := it.Empty[int]()notEmpty := func(yield func(int) bool) {yield(1)yield(2)}result := it.CoalesceSeqOrEmpty(empty1, empty2, notEmpty)// result is the notEmpty sequenceresult2 := it.CoalesceSeqOrEmpty(empty1, empty2)// result2 is an empty sequencePrototypes:func Empty[T any]() iter.Seq[T]func IsEmpty[T any](collection iter.Seq[T]) boolfunc IsNotEmpty[T any](collection iter.Seq[T]) boolfunc CoalesceSeq[T any](v ...iter.Seq[T]) (iter.Seq[T], bool)func CoalesceSeqOrEmpty[T any](v ...iter.Seq[T]) iter.Seq[T]