-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept functions as interfaces #26
Comments
@bsideup hmm, I am not sure I understood what's going on from the code. Can you please elaborate? |
@ahmetalpbalkan yes, I will try :) Currently what we have in Go-linq: We receive func with T (aka interface{}) signature, then users almost always perform casting: over18Names, err := From(students)
.Where(func (s T) (bool,error){
return s.(*Student).age >= 18, nil
})
.Select(func (s T) (T,error){
return s.(*Student).name, nil
}).Results() But, since casting is a must, we can move it into the go-linq and allow users to specify type on func's signature, so this code will look like this: over18Names, err := From(students)
.Where(func (s Student) (bool,error){
return s.age >= 18, nil
})
.Select(func (s Student) (T,error){
return s.name, nil
}).Results() Technically it's possible with reflection. I you want I can implement it and send as a pull request :) |
@bsideup ooh interesting. What would be the method signatures for |
@bsideup If you're still interested, I'd love to see a prototype. It appears like this would make these methods accept |
@ahmetalpbalkan sorry for no response for a long time, was busy a little bit actually, I did some research, and it looks like reflection will affect performance :( Also, I found this great post about it: |
Hi!
First of all, thanks for go-linq, it's awesome :)
Since there are no generics in Golang, we have to deal with interface{}-s.
I just spotted nice hack in Glow project to allow users to specify types on parameters themself:
https://github.com/chrislusf/glow/blob/master/flow/dataset_map.go#L19-L47
Seems like a really great idea to steal :)
The text was updated successfully, but these errors were encountered: