This LINQ implementation is unique in that it is not related to any particular data structure.<p>The LINQ code in C# found at <a href="https://docs.microsoft.com/dotnet/api/system.linq.enumerable.range" rel="nofollow">https://docs.microsoft.com/dotnet/api/system.linq.enumerable...</a>
can be written in Go with this implementation as follows:<p><pre><code> // Generate a sequence of integers from 1 to 10 and then select their squares.
squares := Range(1, 10).Select(func(x Any) Any { return x.(int) * x.(int) })
squares(func(num Any) {
fmt.Println(num)
})
</code></pre>
Here the function Range is defined as follows:<p><pre><code> // Range creates an Enumerator which counts from start
// up to start + count - 1.
func Range(start, count int) Enumerator {
end := start + count
return func(yield func(Any)) {
for i := start; i < end; i++ {
yield(i)
}
}
}
</code></pre>
Note that Enumerator is just a function type defined as func(func(Any)).
The space complexity is O(1) and you can yield values infinitely if you want.