4 ms·
Worth noting that the syntax example is slightly incorrect. Since go auto-postpends ; to lines, you must have a trailing . on the line to allow the compiler to
by shadowmint 13y ago
Worth noting that the syntax example is slightly incorrect.
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)