O'Reilly logo

Domain Modeling Made Functional by Scott Wlaschin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Composition

We discussed “composition” in the context of types—creating new types by combining other types. Now let’s talk about function composition, combining functions by connecting the output of the first to the input of the second.

For example, here are two functions. The first takes an apple as input and outputs a banana. The second takes a banana as input and outputs some cherries. The output of the first is the same type as the input of the second, and therefore we can compose them together like this:

images/fn_compose_before.png

After we have composed them together, we have a new function:

An important aspect of this kind of composition is information hiding. You ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required