Skip to content

Commit

Permalink
Bugfix in WhereIndexed() (#88)
Browse files Browse the repository at this point in the history
* fixes #86

* fix example tests

* fixed formatting
  • Loading branch information
kalaninja authored and ahmetb committed Oct 28, 2019
1 parent b1b02a1 commit 80a9834
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ func ExampleQuery_WhereIndexed() {

fmt.Println(query)
// Output:
// [0 15 40]
// [0 20 15 40]
}

// The following code example demonstrates how to use the Zip
Expand Down Expand Up @@ -2506,7 +2506,7 @@ func ExampleQuery_WhereIndexedT() {

fmt.Println(query)
// Output:
// [0 15 40]
// [0 20 15 40]
}

// The following code example demonstrates how to use the Zip
Expand Down
1 change: 1 addition & 0 deletions where.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(index, item) {
index++
return
}

Expand Down
3 changes: 3 additions & 0 deletions where_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestWhereIndexed(t *testing.T) {
{"sstr", func(i int, x interface{}) bool {
return x.(rune) != 's' || i == 1
}, []interface{}{'s', 't', 'r'}},
{"abcde", func(i int, _ interface{}) bool {
return i < 2
}, []interface{}{'a', 'b'}},
}

for _, test := range tests {
Expand Down

0 comments on commit 80a9834

Please sign in to comment.