10 tips to write fast stack-safe functional code in Scala: the automatic-batch… - Christophe Calvès
Channel: ScalaIO FR
Date: 14/12/2019

10 tips to write fast stack-safe functional code in Scala: the automatic-batching library experience report


Have you ever heard the belief of functional programming being slow? Have you ever been caught by a `StackOverflowError` in your recursive functions? Have you ever rewritten your functional code into imperative style to make it fast and stack-safe? What if i told you how to write fast and stack-safe functional code? Even for non tail-recursive functions! ;) In this talk i'll present you 10 tips to write fast and stack-safe functional code. It is based on my experience implementing [Auto-Batch](https://github.com/chrilves/auto-batch), a pure functional-programming Scala library to automatically batch API calls. Through these 10 tips, we'll discuss many subjects together: what `@tailrec` really means and how to bypass it, how to make most functions tail-recursive, how to be sure your code is really stack-safe, which free data-structure to choose for your need, how to use smart constructors to speed things up, "hidden" features of the IO monads, applicatives vs monads, why parametricity is your friend, are Generalized Algebraic Data Types really useful (spoiler alert, they are!), is there a concrete use-case of continuation-passing style, ...