Comments (7)
Hmm this looks legitimate. So you're saying this is a variable reused unintentionally?
Do you mind adding a test case for it so we can clearly see this fail. I'm also surprised we don't have such a case unit tested already.
from go-linq.
hi, here's the test case:
I think index behavior should be the same no matter what predicate is provided. otherwise, we could not do index-based filtering
with WhereIndexed
thanks
package main
import (
"testing"
"github.com/ahmetb/go-linq/v3"
)
var l = []string{"a", "b", "c", "d"}
// this will fail
func TestWhereIndexedWithTruePredicate(t *testing.T) {
var idx int
linq.From(l).WhereIndexed(func(i int, _ interface{}) bool {
if i != idx {
t.Errorf("i should be increased like idx in WhereIndexed with true predicate. expected(%v), got(%v)", idx, i)
}
idx++
return true
}).Results()
}
// this will pass
func TestWhereIndexedWithFalsePredicate(t *testing.T) {
var idx int
linq.From(l).WhereIndexed(func(i int, _ interface{}) bool {
if i != idx {
t.Errorf("i should be increased like idx in WhereIndexed with false predicate. expected(%v), got(%v)", idx, i)
}
idx++
return false
}).Results()
}
// suppose there's no different between ForEachIndexed and WhereIndexed as for index behavior
// this will pass
func TestForEachIndexed(t *testing.T) {
var idx int
linq.From(l).ForEachIndexed(func(i int, _ interface{}) {
if i != idx {
t.Errorf("i should be increased like idx in ForEachIndexed. expected(%v), got(%v)", idx, i)
}
idx++
})
}
from go-linq.
hi, here's the test case:
sorry I meant to say, can you send a PR with this test case?
from go-linq.
Line 32 in b1b02a1
for example we have this test case, you can add it next to that.
also do you have any idea why this test case passes? sorry I'm rusty a bit on this codebase.
from go-linq.
hi @ahmetb , here's the PR:
what I'm confused is all about the picture below
from go-linq.
Yeah I'm surprised the [9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}
test is passing but yours in #87 isn't.
The part you highlighted seems accurate. First param passed to predicate
is the index of element (starting from 0) in the collection, second param is its value.
from go-linq.
If the highlighted part is accurate, then I'm sure there's bug in WhereIndexed
from go-linq.
Related Issues (20)
- Append方法优化
- "GroupBy has better performance than GroupByT" is written on the document,why?
- ToChannelT release? HOT 2
- why union.go file doesn't have func UnionBy like the func IntersectBy in intersect.go
- Why `ToSlice` need a custom grow strategy instead of the standard library? HOT 1
- runtime error: hash of unhashable type map[string]interface {} HOT 9
- Unit test ExampleOrderedQuery_ThenByDescending fails on golang-1.19.2 HOT 6
- sort result is unexpected HOT 1
- How to implement the full join function of SQL
- new generic functions type HOT 1
- 转换错误 HOT 1
- I expect the data queried using gorm to be converted using go-linq HOT 1
- Article comparing performance of go-linq vs others HOT 4
- gopkg.in/ahmetb/go-linq.v3: gopkg.in/ahmetb/[email protected]: parsing go.mod: module declares its path as: github.com/ahmetb/go-linq/v3 but was required as: gopkg.in/ahmetb/go-linq.v3 HOT 5
- how about add parameter timeout for FromChannelT?
- Try out the new Go generics proposal with go-linq HOT 14
- Is it safe to copy in multiple concurrency HOT 2
- How to implement complex SQL functions HOT 5
- PLINQ support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-linq.