Hi folks,
After reading number of historical threads in this group about how unsuitable Go is for something like LINQ (language integrated query) since there are no generics and lambdas, I funnily decided to do this anyway –and it is finally here. This is my first project in Go. Please check it out:
The library provides methods to query and manipulate objects in in-memory slices, inspired by Microsoft's LINQ library. There are similar projects for Go like
fn and
gen where one is functional tools and other provides LINQ-like functionality with code generation for type safety, respectively. Here are highlights about what I have built:
* DRY: If your code has a significant SQL-like operations for in-memory objects, this library might help you to do not repeat yourself.
* Accepts slices of any type: There's a reflection hack makes this possible.
* No type safety: You have to make assertions to the type you expect in all predicate/selector functions. Type assertion makes it just a bit slower. Also, need to have 100% code coverage for LINQ code you are writing.
* Parallelization: I implemented PLINQ (parallel linq) using goroutines. So this actually might have a real use in Go projects. There's an example in the
wiki about this.
* Strict error handling: Since queries may involve IO operations or calls to other packages, you will see a lot of error parameters here and there. It makes things a lot uglier but Go-ish. I am looking for ways to reduce it without restricting users any further on strict error handling.
* Hard to debug: Since you will end up a query method chain like From().Where().Select().Count(), any error occurred during the query will be returned at the very end propagating through all the methods in the rest of the chain. But it's the same case in .NET anyways, I kept this approach as-is.
I call it v0.9 at this point and I believe you guys might kindly provide some feedback to improve it. It also seems to me like such project has no place in Go ecosystem but a day might come where we can have generics (or even lambdas) and then there will be people who can make use of this library. However, current state of Go is not making things any easier for such type of programs, I suppose there is no harm in doing this project and my motivation was to be just make something useful out of my time.
There are already a few kind tweets about it:
So, I appreciate your feedback, contributions and stars.
Regards,
Alp.
p.s. you might say it's not really 'language integrated' but Microsoft
uses the term LINQ for method syntax as well.