docs/data/it-map.md
Transforms a sequence to another type by applying a transform function to each element.
Examples:
seq := func(yield func(int) bool) {
_ = yield(1)
_ = yield(2)
_ = yield(3)
}
mapped := it.Map(seq, func(x int) string {
return fmt.Sprintf("item-%d", x)
})
var result []string
for v := range mapped {
result = append(result, v)
}
// result contains "item-1", "item-2", "item-3"
Transforms a sequence to another type by applying a transform function to each element and its index.
seq := func(yield func(int) bool) {
_ = yield(10)
_ = yield(20)
_ = yield(30)
}
mapped := it.MapI(seq, func(x int, index int) string {
return fmt.Sprintf("item-%d-%d", x, index)
})
var result []string
for v := range mapped {
result = append(result, v)
}
// result contains "item-10-0", "item-20-1", "item-30-2"