Video recording of a talk I gave on functional programming at a Scala Central meetup.
Learning (and subsequently trying to explain) monads has become something of a rite of passage in functional programming. Burrito analogies aside, the most helpful description I have come across is given by Noel Welsh and Dave Gurnell in Scala with Cats:
“A monad is a mechanism for sequencing computations.”
Case classes provide a convenient way of working with immutable objects in scala. Manipulating fields within them can be tedious, however. In this post, we will look at how lenses can be used to abstract over this complexity while preserving the benefits of immutability.
Monoids are used to describe an aggregation pattern: whenever we need to combine values of a particular type, a monoid instance helps abstract the mechanics of the aggregation from the program’s business logic. In this post, we will use the LCD Digits kata that we tackled previously as a motivating example for applying this pattern. The goal here is to transform a sequence of input digits into a string resembling their representation on an LCD display.
Using functions to express musical ideas is nothing new: Harmony, time signatures, the relations between notes in a scale and musical form all have their roots in mathematics, and composers have used mathematical abstractions for millennia (see Pythagorean Tuning for a 2500-year-old example). These abstractions, however, are not always obvious from they way that music is written down, leading to a potential disconnect between composer and performer. In this post, we will use Steve Reich’s 1972 Clapping Music to show how functional programming can be used to capture an underlying musical idea.
I recently attended one of the coding dojos run by the London Scala User Group. It was great fun, and I’d recommend getting involved to anyone who’s interested in meeting other developers and learning more about scala and functional programming. After breaking into groups, we set about tackling the ‘LCD Digits’ problem from cyber-dojo.org. Although fairly straightforward as a programming challenge, it offers a number of ways to experiment with different functional idioms. The goal is to write a program that takes an integer, and formats this as a string composed of the ‘.’, ‘_’, “|’ and ” ” characters so that the output resembles an LCD display.