FAQ
I'm not going to discuss it in this thread, which is spiraling out of
control, but there's no reason you can't chain methods in go, passing an
interface as a return type and doing a type assertion on the result, like:

var blah = package.GetAggregate()
var subset, err = linq.From(blah).Where(func(x T) bool { return x.Value ==
10 }).Select(func(x T) []interface{} { return []interface{} { x.Value,
x.Name }).OrderBy(func(x1 T, x2 T) bool { return x1.Value > x2.Value
}).Result()
var typed_subset = subset.([]int)

Notice you need the .Result() to collect errors and the final result from
the data set.

the closure syntax isn't as pretty as in C# or python, where you can x =>
x.Value == ?, but it *does* work.

You could get pretty far down the road of writing a linq library if you
wanted to.

If you want to talk about it practically, start a new thread with a
different topic.

~
Doug.
On Saturday, May 18, 2013 6:41:48 AM UTC+8, Sod Almighty wrote:


On Friday, May 17, 2013 11:15:58 PM UTC+1, kortschak wrote:


As another apporach to your question, similar to Ian's would be to take a
pointer to an interface{} and plase the results in that. This is used in a
number of places in the standard library. This would depend on reflection,
but you could take an interfaced-based approach like Foo(a, b Interface, c
SetInterface) where a and b satisfy the behaviours you need to het the
inputs and SetInterface satisfies the behaviour of storing that result.
Potentially no type assertions are needed under this scheme.
Yeah, but you can't do:

results := values.where( ...filter function... ).orderby( ...sorting
function... ).select( ...transformation function... )

With your Foo function, it's a laborious job of one-operation-per-line,
plus a bunch of typecasts. Yeah, I realise that with enough work and
messing about it's possible to write a function Foo(), but that's not what
I intended here. My intention was to allow for a simple SQL-like query
syntax, in the style of .NET LINQ. Because doing it imperatively is hard
work and less readable. Also potentially slower (if it resolves the queries
immediately).
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2021 Grokbase