Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hsldymq committed Sep 3, 2024
1 parent 9b7f561 commit e8e2b9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions funcs_aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

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

func TestScan(t *testing.T) {
iterable := NewIterableFromSlice([]int{1, 2, 3, 4, 5})
iterable := newIterableFromSlice([]int{1, 2, 3, 4, 5})
e := Scan(iterable, 0, func(acc, each int) int {
return acc + each
})
Expand Down
16 changes: 8 additions & 8 deletions funcs_grouping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func TestJoin(t *testing.T) {
Major string
}

students := NewIterableFromSlice([]student{
students := newIterableFromSlice([]student{
{"1", "Alice"},
{"2", "Bob"},
{"3", "Cindy"},
})
majors := NewIterableFromSlice([]studentMajor{
majors := newIterableFromSlice([]studentMajor{
{"1", "Math"},
{"1", "Physics"},
{"2", "English"},
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestJoin(t *testing.T) {
t.Fatalf("test Join, expect: %v, actual: %v", expect, actual)
}

students = NewIterableFromSlice([]student{})
students = newIterableFromSlice([]student{})
e = Join(students, majors, func(s student) string {
return s.ID
}, func(m studentMajor) string {
Expand All @@ -79,12 +79,12 @@ func TestJoinAs(t *testing.T) {
Name string
Major string
}
students := NewIterableFromSlice([]student{
students := newIterableFromSlice([]student{
{"1", "Alice"},
{"2", "Bob"},
{"3", "Cindy"},
})
majors := NewIterableFromSlice([]studentMajor{
majors := newIterableFromSlice([]studentMajor{
{"1", "Math"},
{"1", "Physics"},
{"2", "English"},
Expand Down Expand Up @@ -127,12 +127,12 @@ func TestGroupJoin(t *testing.T) {
Major string
}

students := NewIterableFromSlice([]student{
students := newIterableFromSlice([]student{
{"1", "Alice"},
{"2", "Bob"},
{"3", "Cindy"},
})
majors := NewIterableFromSlice([]studentMajor{
majors := newIterableFromSlice([]studentMajor{
{"1", "Math"},
{"1", "Physics"},
{"2", "English"},
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestGroupJoin(t *testing.T) {
t.Fatalf("test GroupJoin, expect: %v, actual: %v", expect, actual)
}

students = NewIterableFromSlice([]student{})
students = newIterableFromSlice([]student{})
e = GroupJoin(students, majors, func(s student) string {
return s.ID
}, func(m studentMajor) string {
Expand Down
16 changes: 8 additions & 8 deletions iterable.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import (
"iter"
)

func NewIterableFromSlice[T any](slice []T) Iterable[T] {
return &sliceIterable[T]{s: slice}
}

func NewIterableFromSeq[TIter goiter.SeqX[T], T any](iter TIter) Iterable[T] {
return &seqIterable[TIter, T]{iter: iter}
}

type Iterable[T any] interface {
Iter() iter.Seq[T]
}

func newIterableFromSlice[T any](slice []T) Iterable[T] {
return &sliceIterable[T]{s: slice}
}

type sliceIterable[T any] struct {
s []T
}
Expand All @@ -25,6 +21,10 @@ func (si *sliceIterable[T]) Iter() iter.Seq[T] {
return goiter.SliceElems(si.s).Seq()
}

func newIterableFromSeq[TIter goiter.SeqX[T], T any](iter TIter) Iterable[T] {
return &seqIterable[TIter, T]{iter: iter}
}

type seqIterable[TIter goiter.SeqX[T], T any] struct {
iter TIter
}
Expand Down

0 comments on commit e8e2b9c

Please sign in to comment.