mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.0 KiB
1.0 KiB
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CoalesceSeqOrEmpty | coalesceseqorempty | it/type_manipulation.go#L76 | it | type |
|
|
|
102 |
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, 2
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 = it.CoalesceSeqOrEmpty(emptyStrSeq, strSeq)
// iter.Seq[string] yielding "a", "b"
result = it.CoalesceSeqOrEmpty(emptySeq, emptyStrSeq)
// empty sequence (yields nothing)