mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.2 KiB
1.2 KiB
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| RejectMap | rejectmap | it/seq.go#L608 | it | sequence |
|
|
|
42 |
Maps elements of a sequence to new values and rejects elements where the callback returns true. Only elements where the second return value is false are included in the result.
seq := func(yield func(int) bool) {
yield(1)
yield(2)
yield(3)
yield(4)
}
result := it.RejectMap(seq, func(x int) (string, bool) {
if x%2 == 0 {
return fmt.Sprintf("even-%d", x), true // reject even numbers
}
return fmt.Sprintf("odd-%d", x), false
})
// iter.Seq[string] yielding "odd-1", "odd-3"
seq = func(yield func(string) bool) {
yield("a")
yield("")
yield("c")
yield("d")
}
result = it.RejectMap(seq, func(s string) (int, bool) {
if s == "" {
return 0, true // reject empty strings
}
return len(s), false
})
// iter.Seq[int] yielding 1, 1, 1 (length of "a", "c", "d")