Back to Lo

It Coalesceseq

docs/data/it-coalesceseq.md

1.53.0702 B
Original Source

Returns the first non-empty sequence from the provided arguments, with a boolean indicating if a non-empty sequence was found.

go
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, true

emptyStrSeq := 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", true

result, ok = it.CoalesceSeq(emptySeq, emptyStrSeq)
// nil sequence, false