docs/data/it-rejectmap.md
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")