For HWS+ subscribers: Memoization caches function results so the same work never runs twice, and Swift's closures and generics make it elegant to implement. https://www.hackingwithswift.com/plus/high-performance-apps/using-memoization-to-speed-up-slow-functions