Inside DrMark’s Lab

Inside DrMark’s Lab

Deferred Desires with Typelevel Cats

Now, later, or always—choose your evaluation kink

The Unshielded Mind's avatar
The Unshielded Mind
Sep 06, 2025
∙ Paid

The Eval monad in Cats gives developers control over how and when computations are evaluated. Unlike plain Scala expressions, Eval lets you select whether a value should be computed eagerly, lazily with caching, or lazily without caching. It also ensures stack safety for recursive computations. Exploring Eval through practical examples shows how it can be applied in realistic code construction rather than remaining a theoretical construct.

Evaluation Strategies

Eval offers three main strategies. Eval.now is eager and computes the value immediately, keeping it stable forever. Eval.later delays computation until the first access and caches the result for later use. Eval.always recomputes on every access, which makes it useful when the underlying state changes or randomness is involved. In addition, Eval.defer suspends evaluation of another Eval, which is critical for stack safety in recursion. Consider the following code that highlights the different strategies - the code is available in my Github repo.

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2026 Markgrechanik@gmail.com · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture