FPOO Chapter 7: Programming with Dataflow

Note: This article is part of a series working through the exercises in Brian Marick's "Functional Programming for the Object-Oriented Programmer", in Elixir instead of Clojure. The full notes and source code are on GitHub.

This is where FPOO starts to get interesting. I have to say I find the choice of the term “dataflow” confusing due to its other associations in programming. But this section introduces a style of working with data–first annotating it, then filtering it–which I’ve never really given a lot of thought to.

I’m going to start out by defining a record type for courses. Marick doesn’t do this for his example, but Clojure has more shortcuts for working with raw maps (e.g. being able to use a key as a function of the map). I’m curious if this kind of dataflow programming is easy to adapt to records.

Let me just make sure I know how to use records.

OK, now on to the first metadata-annotating function.

And now the second. This one differs from the first in that it assumes it will get keyword lists instead of a records. This is a strike against using records in the first place, since now these two functions differ in this seemingly arbitrary way.

And now the final annotation function, which adds notes on course availability.

I’m pleasantly surprised I can use the capture operator for the nested &not(empty?(&1)) expression.

Finally, the payoff. At this point the book introduces the arrow (->) operator for threading functions together, but of course this is Elixir so we do that all the time.

I’m tired of translating now, but I’m going to do one quick check that this works as expected.

(I’d really like to find a way to avoid having to explicitly alias the Course type, and instead have it show up when importing the Scheduling module it lives in.)

This has been instructive, but time-consuming. Enough for now.