June 2018
Intermediate to advanced
280 pages
7h 46m
English
Tail call optimization (TCO) is a technique used by some compilers to call a function without using stack space. Scala makes use of it by annotating the recursive code with the @tailrec annotation. This basically tells the compiler to use a special loop, called trampoline, that repeatedly runs functions. A function call could be in one of the states—done or more to call. On done, it returns the result (head), and on more, it returns the current loop without the head (tail). This pattern is already made available to us by the cyclops-react library.
Read now
Unlock full access