Skip to content

Commit

Permalink
limit: swap parameters in signature
Browse files Browse the repository at this point in the history
passing the limit first and the source iterator second is more
ergonomic.
  • Loading branch information
0x5a17ed committed May 27, 2024
1 parent 232db95 commit a5b5be3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion itlib/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestChunk(t *testing.T) {
"A", "B", "C", "D", "E", "F", "G",
},
tx: func(el itkit.Iterator[string]) itkit.Iterator[string] {
return itlib.Limit(el, 2)
return itlib.Limit(2, el)
},
exp: [][]string{
{"A", "B"},
Expand Down
2 changes: 1 addition & 1 deletion itlib/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ func newLimitIterator[T any](n uint, src itkit.Iterator[T]) *LimitIterator[T] {
}

// Limit returns a new [LimitIterator] instance.
func Limit[T any](src itkit.Iterator[T], n uint) itkit.Iterator[T] {
func Limit[T any](n uint, src itkit.Iterator[T]) itkit.Iterator[T] {
return newLimitIterator(n, src)
}
6 changes: 3 additions & 3 deletions itlib/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func TestLimit(t *testing.T) {
t.Run("empty", func(t *testing.T) {
it := itlib.Limit(itlib.Empty[any](), 10)
it := itlib.Limit(10, itlib.Empty[any]())
assert.False(t, it.Next())
})

Expand All @@ -34,7 +34,7 @@ func TestLimit(t *testing.T) {

src := rangeit.Range(10)

it := itlib.Limit(src, 4)
it := itlib.Limit(4, src)

asserter.Equal([]int{0, 1, 2, 3}, sliceit.To(it))

Expand All @@ -49,7 +49,7 @@ func TestLimit(t *testing.T) {

src := rangeit.Range(4)

it := itlib.Limit(src, 10)
it := itlib.Limit(10, src)

asserter.Equal([]int{0, 1, 2, 3}, sliceit.To(it))

Expand Down
4 changes: 2 additions & 2 deletions itlib/tee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestTee(t *testing.T) {
it := funcit.PullFn(func() (*int, bool) {
return c.new(), true
})
it = itlib.Limit(it, 10)
it = itlib.Limit(10, it)

l, r := itlib.Tee(it)

Expand All @@ -161,7 +161,7 @@ func TestTee(t *testing.T) {
asserter.Equal(c.n, uint32(10))

// Consume half on the right side.
s := sliceit.To(itlib.Limit(r.Iter(), 5))
s := sliceit.To(itlib.Limit(5, r.Iter()))
asserter.Len(s, 5)

// Force garbage collection to clean up references.
Expand Down

0 comments on commit a5b5be3

Please sign in to comment.