private static ExpressionGroup OptimizeGroup(Dictionary <Expression, CachedExpression> cache, ExpressionGroup group) { // TODO: Generalise this somehow? switch (group) { case Persist p: return(new Persist(p.State.Select(s => OptimizeSingle(cache, s.InitialValue)), _ => p.NewValue.Select(n => OptimizeSingle(cache, n)))); case Loop l: return(new Loop(l.State.Select(s => OptimizeSingle(cache, s.InitialValue)), _ => OptimizeSingle(cache, l.Condition), _ => l.Body.Select(n => OptimizeSingle(cache, n)))); default: return(group); } }