Skip to content

Commit 9e5dba8

Browse files
committed
Support Map in itx to allow limited chaining
1 parent e8c6305 commit 9e5dba8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

it/itx/map.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package itx
22

33
import "github.com/BooleanCat/go-functional/v2/it"
44

5+
// Map is a convenience method [it.Map] returning an [Iterator] to support
6+
// chaining.
7+
func Map[V any, W any](iterator func(func(V) bool), f func(V) W) Iterator[W] {
8+
return Iterator[W](it.Map(iterator, f))
9+
}
10+
511
// Transform is a convenience method for chaining [it.Map] on [Iterator]s where
612
// the provided functions argument type is the same as its return type.
713
//

it/itx/map_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ package itx_test
33
import (
44
"fmt"
55
"maps"
6+
"slices"
67

78
"github.com/BooleanCat/go-functional/v2/it/itx"
89
)
910

11+
func ExampleMap() {
12+
fmt.Println(itx.Map(slices.Values([]int{0, 1, 2}), func(v int) int {
13+
return v + 1
14+
}).Collect())
15+
// Output: [1 2 3]
16+
}
17+
1018
func ExampleIterator_Transform() {
1119
fmt.Println(itx.FromSlice([]int{0, 1, 2}).Transform(func(v int) int {
1220
return v + 1

0 commit comments

Comments
 (0)