Skip to content

Commit 0887257

Browse files
committed
Simplify iterator chaining for ForEach
1 parent a984430 commit 0887257

28 files changed

+15
-321
lines changed

iter/chain.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ func (iter *ChainIter[T]) Next() option.Option[T] {
3535

3636
var _ Iterator[struct{}] = new(ChainIter[struct{}])
3737

38-
// ForEach is a convenience method for [ForEach], providing this iterator as an
39-
// argument.
40-
func (iter *ChainIter[T]) ForEach(callback func(T)) {
41-
ForEach[T](iter, callback)
42-
}
43-
4438
// ForEach is a convenience method for [Find], providing this iterator as an
4539
// argument.
4640
func (iter *ChainIter[T]) Find(predicate func(T) bool) option.Option[T] {

iter/chain_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ func TestChainExhausted(t *testing.T) {
4646
assert.Equal(t, delegate2.NextCallCount(), 1)
4747
}
4848

49-
func TestChainForEach(t *testing.T) {
50-
total := 0
51-
52-
iter.Chain[int](iter.Lift([]int{1, 2}), iter.Lift([]int{3, 4})).ForEach(func(number int) {
53-
total += number
54-
})
55-
56-
assert.Equal(t, total, 10)
57-
}
58-
5949
func TestChainFind(t *testing.T) {
6050
number := iter.Chain[int](iter.Lift([]int{1, 2}), iter.Lift([]int{3, 4})).Find(func(number int) bool {
6151
return number == 3

iter/channel.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ func (iter *ChannelIter[T]) Next() option.Option[T] {
2929

3030
var _ Iterator[struct{}] = new(ChannelIter[struct{}])
3131

32-
// ForEach is a convenience method for [ForEach], providing this iterator as an
33-
// argument.
34-
func (iter *ChannelIter[T]) ForEach(callback func(T)) {
35-
ForEach[T](iter, callback)
36-
}
37-
3832
// Find is a convenience method for [Find], providing this iterator as an
3933
// argument.
4034
func (iter *ChannelIter[T]) Find(predicate func(T) bool) option.Option[T] {

iter/channel_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,6 @@ func TestFromChannelEmpty(t *testing.T) {
4646
assert.True(t, iter.FromChannel(ch).Next().IsNone())
4747
}
4848

49-
func TestFromChannelForEach(t *testing.T) {
50-
ch := make(chan int)
51-
52-
go func() {
53-
defer close(ch)
54-
ch <- 1
55-
ch <- 2
56-
ch <- 3
57-
}()
58-
59-
total := 0
60-
61-
iter.FromChannel(ch).ForEach(func(number int) {
62-
total += number
63-
})
64-
65-
assert.Equal(t, total, 6)
66-
}
67-
6849
func TestFromChannelFind(t *testing.T) {
6950
ch := make(chan int)
7051

iter/counter.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ func (c *CountIter) Next() option.Option[int] {
2525

2626
var _ Iterator[int] = new(CountIter)
2727

28-
// ForEach is a convenience method for [ForEach], providing this iterator as an
29-
// argument.
30-
func (iter *CountIter) ForEach(callback func(int)) {
31-
ForEach[int](iter, callback)
32-
}
33-
3428
// Find is a convenience method for [Find], providing this iterator as an
3529
// argument.
3630
func (iter *CountIter) Find(predicate func(int) bool) option.Option[int] {

iter/counter_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ func TestCount(t *testing.T) {
2828
assert.Equal(t, counter.Next().Unwrap(), 2)
2929
}
3030

31-
func TestCountForEach(t *testing.T) {
32-
defer func() {
33-
assert.Equal(t, recover(), "oops")
34-
}()
35-
36-
iter.Count().ForEach(func(_ int) {
37-
panic("oops")
38-
})
39-
40-
t.Error("did not panic")
41-
}
42-
4331
func TestCountFind(t *testing.T) {
4432
assert.Equal(t, iter.Count().Find(func(number int) bool {
4533
return number == 5

iter/cycle.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ func (iter *CycleIter[T]) Next() option.Option[T] {
5252

5353
var _ Iterator[struct{}] = new(CycleIter[struct{}])
5454

55-
// ForEach is a convenience method for [ForEach], providing this iterator as an
56-
// argument.
57-
func (iter *CycleIter[T]) ForEach(callback func(T)) {
58-
ForEach[T](iter, callback)
59-
}
60-
6155
// Find is a convenience method for [Find], providing this iterator as an
6256
// argument.
6357
func (iter *CycleIter[T]) Find(predicate func(T) bool) option.Option[T] {

iter/cycle_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ func TestCycleExhausted(t *testing.T) {
4040
assert.Equal(t, delegate.NextCallCount(), 1)
4141
}
4242

43-
func TestCycleForEach(t *testing.T) {
44-
defer func() {
45-
assert.Equal(t, recover(), "oops")
46-
}()
47-
48-
iter.Cycle[int](iter.Lift([]int{1, 2})).ForEach(func(_ int) {
49-
panic("oops")
50-
})
51-
52-
t.Error("did not panic")
53-
}
54-
5543
func TestCycleFind(t *testing.T) {
5644
assert.Equal(t, iter.Cycle[int](iter.Lift([]int{1, 2})).Find(func(number int) bool {
5745
return number == 2

iter/drop.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ func (iter *DropIter[T]) delegateNext() option.Option[T] {
4949

5050
var _ Iterator[struct{}] = new(DropIter[struct{}])
5151

52-
// ForEach is a convenience method for [ForEach], providing this iterator as an
53-
// argument.
54-
func (iter *DropIter[T]) ForEach(callback func(T)) {
55-
ForEach[T](iter, callback)
56-
}
57-
5852
// Find is a convenience method for [Find], providing this iterator as an
5953
// argument.
6054
func (iter *DropIter[T]) Find(predicate func(T) bool) option.Option[T] {

iter/drop_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ func TestDropExhaustedLater(t *testing.T) {
5050
assert.Equal(t, delegate.NextCallCount(), 3)
5151
}
5252

53-
func TestDropForEach(t *testing.T) {
54-
total := 0
55-
56-
iter.Lift([]int{1, 2, 3, 4}).Drop(1).ForEach(func(number int) {
57-
total += number
58-
})
59-
60-
assert.Equal(t, total, 9)
61-
}
62-
6353
func TestDropFind(t *testing.T) {
6454
assert.Equal(t, iter.Drop[int](iter.Count(), 5).Find(func(number int) bool {
6555
return number%4 == 0

0 commit comments

Comments
 (0)