NewThe Detector Was Not Impressed cloudmark

Theme 032016–2021Functional programming

From closures to lambda calculus to ZIO.

8 posts

Functional Programming to the max

A small number guessing game, rewritten step by step from procedural code into a functional program with its own IO type. The aim is not purity for its own sake, but more principled code.

Performant Functional Programming to the max with ZIO

Wile E. Coyote wants a purchase summary for every ACME customer. The same program is built imperatively, then with monad transformers, then with ZIO, which keeps it pure without paying for it at runtime.

Computation Context - Walk the Line

Pierre the tightrope walker and his birds, simulated with exceptions, nulls and finally an Option. Functional programming turns out to be more than a refactor: a computation context gives you honest types and safe sequencing.

Lambda Calculus is Dead! Long live Lambda Calculus!

Lambda calculus is usually shown off with numbers and recursion. Here it goes to work on an everyday CMS problem instead: finding every URL for the sitemap, and each page's alternate language URLs.

Functions as Data

A set library where each set is nothing but a function that says yes or no to an element. Union, intersection and difference follow naturally, and the line between code and data starts to blur.

Houses, Arrays and Higher Order Functions

Filter, map and reduce, put to work on a dataset of house listings. Four-bedroom houses in Cambria or the average listing price take a few composed functions, and maybe turn up a dream home.

Higher Order Functions in Practice

Summing integers, cubes and factorials starts as three near-identical functions. A higher order function folds them into one, showing how JavaScript's first-class functions simplify everyday code.

Data Abstraction and Closures

SICP's picture language, translated from Scheme to JavaScript, where painters are just functions. Combining them with closures builds intricate patterns from simple parts, and shows why stratified design keeps programs easy to change.

Other themes