Lazy Evaluation in Nix: Where Your Conditionals Go to Die | Blog
If you have spent time in traditional programming languages, then you have probably relied on conditionals (if-else, switch, case) at least once in In Nix, as a result of lazy evaluation, many of those constructs become less relevant less relevant—or outright unnecessary. This post dives into why this is the case, and hopes to save you from a few pitfalls that come with this. I first need to explain what Lazy evaluation is. Not just within the context of Nix, but in programming in general. Lazy evaluation means that expressions are not evaluated until their values are actually needed. This is in contrast to strict (or eager) evaluation, where expressions are computed as soon as they are bound to a variable. In more practical terms, lazy evaluation helps avoid unnecessary computations by delaying the evaluation of expressions. It’s a powerful technique for improving performance and managing resources efficiently. In this example lazyNumbers is an infinite list. However, the values are n