Optimized Graph for Scala folding