mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.3 KiB
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 |
|
https://go.dev/play/p/rWZiPB-RZOo |
|
|
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"