Skip to content

Commit e8e2b9c

Browse files
committed
refactor
1 parent 9b7f561 commit e8e2b9c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

funcs_aggregation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestReduce(t *testing.T) {
10-
list := NewIterableFromSeq(goiter.SliceElems([]int{1, 2, 3, 4, 5}))
10+
list := newIterableFromSeq(goiter.SliceElems([]int{1, 2, 3, 4, 5}))
1111
actual := Reduce(list, 0, func(acc, each int) int {
1212
return acc + each
1313
})
@@ -18,7 +18,7 @@ func TestReduce(t *testing.T) {
1818
}
1919

2020
func TestScan(t *testing.T) {
21-
iterable := NewIterableFromSlice([]int{1, 2, 3, 4, 5})
21+
iterable := newIterableFromSlice([]int{1, 2, 3, 4, 5})
2222
e := Scan(iterable, 0, func(acc, each int) int {
2323
return acc + each
2424
})

funcs_grouping_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func TestJoin(t *testing.T) {
1616
Major string
1717
}
1818

19-
students := NewIterableFromSlice([]student{
19+
students := newIterableFromSlice([]student{
2020
{"1", "Alice"},
2121
{"2", "Bob"},
2222
{"3", "Cindy"},
2323
})
24-
majors := NewIterableFromSlice([]studentMajor{
24+
majors := newIterableFromSlice([]studentMajor{
2525
{"1", "Math"},
2626
{"1", "Physics"},
2727
{"2", "English"},
@@ -53,7 +53,7 @@ func TestJoin(t *testing.T) {
5353
t.Fatalf("test Join, expect: %v, actual: %v", expect, actual)
5454
}
5555

56-
students = NewIterableFromSlice([]student{})
56+
students = newIterableFromSlice([]student{})
5757
e = Join(students, majors, func(s student) string {
5858
return s.ID
5959
}, func(m studentMajor) string {
@@ -79,12 +79,12 @@ func TestJoinAs(t *testing.T) {
7979
Name string
8080
Major string
8181
}
82-
students := NewIterableFromSlice([]student{
82+
students := newIterableFromSlice([]student{
8383
{"1", "Alice"},
8484
{"2", "Bob"},
8585
{"3", "Cindy"},
8686
})
87-
majors := NewIterableFromSlice([]studentMajor{
87+
majors := newIterableFromSlice([]studentMajor{
8888
{"1", "Math"},
8989
{"1", "Physics"},
9090
{"2", "English"},
@@ -127,12 +127,12 @@ func TestGroupJoin(t *testing.T) {
127127
Major string
128128
}
129129

130-
students := NewIterableFromSlice([]student{
130+
students := newIterableFromSlice([]student{
131131
{"1", "Alice"},
132132
{"2", "Bob"},
133133
{"3", "Cindy"},
134134
})
135-
majors := NewIterableFromSlice([]studentMajor{
135+
majors := newIterableFromSlice([]studentMajor{
136136
{"1", "Math"},
137137
{"1", "Physics"},
138138
{"2", "English"},
@@ -173,7 +173,7 @@ func TestGroupJoin(t *testing.T) {
173173
t.Fatalf("test GroupJoin, expect: %v, actual: %v", expect, actual)
174174
}
175175

176-
students = NewIterableFromSlice([]student{})
176+
students = newIterableFromSlice([]student{})
177177
e = GroupJoin(students, majors, func(s student) string {
178178
return s.ID
179179
}, func(m studentMajor) string {

iterable.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import (
55
"iter"
66
)
77

8-
func NewIterableFromSlice[T any](slice []T) Iterable[T] {
9-
return &sliceIterable[T]{s: slice}
10-
}
11-
12-
func NewIterableFromSeq[TIter goiter.SeqX[T], T any](iter TIter) Iterable[T] {
13-
return &seqIterable[TIter, T]{iter: iter}
14-
}
15-
168
type Iterable[T any] interface {
179
Iter() iter.Seq[T]
1810
}
1911

12+
func newIterableFromSlice[T any](slice []T) Iterable[T] {
13+
return &sliceIterable[T]{s: slice}
14+
}
15+
2016
type sliceIterable[T any] struct {
2117
s []T
2218
}
@@ -25,6 +21,10 @@ func (si *sliceIterable[T]) Iter() iter.Seq[T] {
2521
return goiter.SliceElems(si.s).Seq()
2622
}
2723

24+
func newIterableFromSeq[TIter goiter.SeqX[T], T any](iter TIter) Iterable[T] {
25+
return &seqIterable[TIter, T]{iter: iter}
26+
}
27+
2828
type seqIterable[TIter goiter.SeqX[T], T any] struct {
2929
iter TIter
3030
}

0 commit comments

Comments
 (0)