Implementing the IEnumerable interface for queries will allow them to be used iterated with foreach loops. This way of iterating is preferred when you need to capture variables outside of the loop as this way doesn't require a closure allocation.
Query<Position, Velocity> query;
float multiplier = 10; // Random variable in outer scope
foreach ((Iter it, Span<Position> p, Span<Velocity> v) in query)
{
foreach (int i in it)
{
p[i].X += v[i].Y * multiplier;
p[i].Y += v[i].Y * multiplier;
}
}
Implementing the
IEnumerableinterface for queries will allow them to be used iterated withforeachloops. This way of iterating is preferred when you need to capture variables outside of the loop as this way doesn't require a closure allocation.