What is a `thunk`?

The answers above are great but in the simplest and most general terms a thunk is a closure that wraps a value or other computations to hide complexity and provide lazy evaluation. @autoclosure is a great example of a thunk: it wraps a function argument in a closure which can be invoked if needed. The work to compute the argument is both hidden and delayed until the argument value is needed, if at all.

12 Likes