Show HN: LINQ for Go
github.com
github.com
What makes LINQ special is IQueryable, e.g. the ability to transform a C# expression at runtime into something else, like a database query. Whenever I see article titles like "LINQ in X", I somehow know that it doesn't refer to IQueryable, which is a pity.
Anyway, these functions should be standard in any modern programming language and because Go is missing such standard functionality is one reason for why I don't like Go. Lack of generics has much to do with it, but also Go's interfaces are weaker than type-classes, combined with Google's disregard for everything we've learned about type-systems in the past 30 years (behold Dart's covariant generics) and so I do have reasons for not holding my breath waiting for a fix. Of course, Go is what many people want, so Go is what many people receive.
I am planning to add SelectMany, ToDictionary, GroupBy and Zip methods soon. I cannot agree you more, I also am not happy about the result I ended up with. Anyway, this was my first project in Go, I will maintain and keep adding stuff to make things easy for other people who might like to use this. But Go is 'really' not for this, I know.
For Android you can use Scala and many people do it. There's a SBT plugin for painless setup and you can work with IntelliJ IDEA as your IDE. Some people even go for Clojure. For iOS, there's RoboVM [1] and you can also use that in combination with Scala - it's very promising.
Java the language sucks, but the JVM and the ecosystem are great and you've got mature languages designed to run on top of it, languages with big communities behind them. Of course, learning a new language and finding the best stuff in a huge ecosystem where choices abound takes time and patience, but I think you'll learn to appreciate it - or if you like C# so much, there's always Xamarin, though it's a little pricey.
It's a real pity that Google didn't go with C# as their language of choice for Android development. The world would suck less. And they actually considered it...
"If Sun doesn't want to work with us, we have two options: 1) Abandon our work and adopt MSFT CLR VM and C# language - or - 2) Do Java anyway and defend our decision, perhaps making enemies along the way"
http://www.fosspatents.com/2011/07/judge-orders-overhaul-of-...
Well it doesn't provide a folding method either, and just about anything can be implemented using a fold.
This has consequences. For example you can't distribute a fold over multiple threads. I'm not very keen on parallel extensions to collections, haven't found a concrete usage for them where it matters, but this does tell you something about folding - it's a low-level operation with which you're back to specifying how instead of what you want. And for collections, at least you've got the flexibility of doing a fold or a foreach painlessly, but for other container types you're out of luck.
SelectMany/flatMap/bind is the defining operation of a Monad, which is a general purpose design pattern that has many uses (e.g. Option, State, Cont, Future, Iteratee, Rx.Observable, etc). It's cool having it, because then you can painlessly filter and transform the values in those containers without pulling them out of their context. To quote Erik Meijer: "Monads are return types that guide you through the happy path".
(Disclaimer, I work with the guy behind it)
Personally these sorts of libraries just strengthen my opinion that golang really needs proper generics. However, if you're already gonna use Go they're pretty neat.
Just leaving this project here. Hopefully, I will maintain it as bugs etc arises. Who knows, maybe someday Go will have these features and there will be many apps instrumenting Go for their application logic and use it.
Eh? Go has lambdas:
func(x int) int { return x * x }(5)Alternate syntax doesn't seem very "Go", so I wouldn't hold my breath!
> Theoretically, there is not much wrong with that.
Understatement in the finest tradition of man pages and RFCs.
I assume people want to use golang for the speed advantages of servicing many connections at once. If each connection is spawning hundreds of goroutines it's not going to work so well.
https://gist.github.com/nathanwdavis/6290428
Basically, for big lists a goroutine per loop is very slow in comparison.
It can't, and there are no generics which is why the input has to be cast back to a Student* in every function. Also why the Sum implementation and the min, max and order (sort) situations are absolutely gross.
Instead I either have to use interfaces and casts (run-time when I would prefer compile-time) or write separate functions for each type (I wrote a Cartesian product library that abstracts the math involved to indexes and lengths, then requires a simple type-specific wrapper simply because of this silly language gap).
Despite that, I still really love Go.
[0] The other being that 1.2 randomly segfaults on my code base during compilation whereas 1.1.2 works fine. For this reason I haven't yet been able to upgrade until I determine the cause.
I found Haskell shortly thereafter and that is where I currently stay ;)
Stringly-typed in what sense?
Personally, I can imagine how someone could live without $conceptname at all. It's as trivial as just never introducing that concept to to the extent they learn it. Or, maybe, that someone knows the concept but unable to use it due to insuperable force, like a lack of necessary tools for target platform(s) or corporate standard dictating what's permitted and what's not.
The point is, this is an unpleasant imagination one don't want to accept. Or something like that. But this is really getting off-topic...
A much more useful comment would have been to describe how crucial $concept is to his programming practice, and how he tried working without $concept but found it a dreadful experience because of $x, $y and $z.
Why, does anyone needs convincing of how useful Generics are?
It's 2014 already.
The purpose of my comment was to draw attention to this.
Since go auto-postpends ; to lines, you must have a trailing . on the line to allow the compiler to consider multiline statements like this as multiline statements instead of multiple (syntactically incorrect) single statements.
I presume this is just done for readability in the docs, but it's a little misleading. Correctly, it would be:
over18Names, err := From(students). // <--- Notice the trailing . to prevent ;
Where(func (s T) (bool,error){
return s.(*Student).age >= 18, nil
}).
Select(func (s T) (T,error){
return s.(*Student).name, nil
}).
Results()
It's argued now and then that this is one of the reasons go isn't useful for chain expression libraries like this; it becomes hard to tell at a glance the difference between two consecutive statements and one chained long statement.(The other reason typically given is it breaks error return expectations, but whatever. I've never really understood what's so hard about simple having the .Final() or .Resolve() or .Results() statement at the end of a chain to get the return code and/or error details shrug)
While personally I don't think I've ever used the LINQ monad syntax, and wish it had been implemented as a generic feature, not every language with support for anonymous functions or closures or function pointers is "LINQ".
Looks like go does not have something similar to extension methods, so a result() call should be put at the end to unwrap the collection.
The lambda syntax is even worst than C++ and no query expressions (aka monad syntax)
Most important: No IQueryable<T> Expression<Func<...>> so doesn't work with remote data sources (SQL, mongo,...)
But the library looks ok given the possibilities
Or you use RethinkDB's RQL approach, which implements a bunch of functions that record what you did, at the cost of not being able to put relatively arbitrary expressions inside the query.
Or how else do you translate ".Where(x -> x.Age > 10)" into SQL?
It's not really "Language INtegrated" if there's no real language aspect, is it?
Was expecting the concision and elegance of LINQ-to-SQL.