2

Persistent Data

So far this has seemed relatively simple. Programs written in the “functional” style are simply programs that have no variables. Rather than reassign values to variables, we use recursion to initialize new function arguments with new values. Simple.

But data elements are seldom as simple as we have so far imagined them to be. So let’s take a look at a slightly more complicated problem, The Sieve of Eratosthenes:

package sieve; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Sieve { boolean[] isComposite; static List<Integer> primesUpTo(int upTo) { return ...

Get Functional Design: Principles, Patterns, and Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.