Skip to content
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

Have Results() return a slice of the original type. #28

Closed
bsht opened this issue Jun 2, 2016 · 1 comment
Closed

Have Results() return a slice of the original type. #28

bsht opened this issue Jun 2, 2016 · 1 comment

Comments

@bsht
Copy link

bsht commented Jun 2, 2016

Currently Results() returns a slice of []T where perhaps a way to get the "original" type of the elements would be more convenient. I constantly find myself having to iterate over the []T to copy all elements to a new slice.

x, err := linq.From(f.Films).Where(func(x linq.T) (bool, error) { return true, nil }).Results()
if err != nil {
 fmt.Println(err)
}

Here x is of type []T and so I cannot reassign it to f.Films. I need to do the following:

f.Films = make([]Film, len(x))
for i, b := range x {
 f.Films[i] = b.(Film)
}

I find myself doing this kind of thing very often when using your package. Perhaps there should be a way to do this included in the package itself?

@ahmetb
Copy link
Owner

ahmetb commented Jun 2, 2016

It is technically not possible to return a []Film from the Results() method due to type system restrictions in Go language. There are similar packages such as https://clipperhouse.github.io/gen/ that generate code for your types, which can achieve what you want.

@ahmetb ahmetb closed this as completed Jun 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants