Files
lo/docs/data/it-map.md
T

1.3 KiB

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
Map map it/seq.go#L51 it sequence
func Map[T, R any](collection iter.Seq[T], transform func(item T) R) iter.Seq[R]
func MapI[T, R any](collection iter.Seq[T], transform func(item T, index int) R) iter.Seq[R]
https://go.dev/play/p/rWZiPB-RZOo
it#sequence#map
it#sequence#mapi
core#slice#map
it#sequence#filtermap
it#sequence#flatmap
20

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"

MapI

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"