Trampolining
Trampolining is a technique that represents chained function calls as iterative steps to avoid growing the call stack.
Functional Programming in Scala, Second Edition
Trampolining is a technique that represents chained function calls as iterative steps so computation can proceed without growing the call stack.
- How it is used
- Uses iterative interpretation to make monadic and function composition stack safe.
- How deep it goes
- Explains constructor-based representation, reassociation, tail-recursive interpretation, and the cost of slower execution.
- Examples
- Demonstrates ordinary function composition, IO constructors, nested FlatMap values, and Scala TailCalls.
- What you can do after
- Build stack-safe compositions by returning TailRec values and interpreting them with run or result.
Read how Functional Programming in Scala, Second Edition explains trampolining →
Functional Programming in JavaScript
A technique for simulating tail recursion by repeatedly invoking thunks or continuations in an iterative loop.
- How it is used
- Uses trampolining to control stack growth when simulating tail recursion in JavaScript.
- How deep it goes
- Defines trampolines and thunks, but stops short of implementation details and recommends further research.
- Examples
- Uses tail-recursive factorial examples to motivate the need for trampolining.
- What you can do after
- Evaluate when trampolining can work around missing native tail-call optimization in JavaScript.
Read how Functional Programming in JavaScript explains trampolining →
Related concepts
- stack overflowaddresses · A stack overflow is a runtime failure caused by exhausting the available capacity of a program’s call stack.
- stack safetyaddresses · Stack safety is the property of an implementation being able to process inputs without exhausting the call stack as input size grows.
- tail-call optimizationaddresses · Tail-call optimization is a compiler or runtime transformation that executes an eligible call in tail position without allocating an additional call-stack frame.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

