Building Our Functional Core

Let’s learn how to build the functional core for the counter.

Diving into our functional core

Now we can finally start coding. Our functional core is what some programmers call the business logic. This inner layer does not care about any of the machinery related to processes. It has the following properties:

  • It doesn’t try to preserve the state.

  • It has no side effects (or, at least, the bare minimum that we must deal with).

  • It’s made up of functions.

Our goal is to deal with complexity in isolation. Processes and side effects add complexity. Building our core allows us to isolate the inherent complexity of our domain from the complexity of the machinery for which we need to manage processes, handle side effects, and the like.

Let’s take a look at some examples:

  • In a chess game, this logic would have functions that take a board, move an individual piece, and return an updated board. It may also have a function to take a board with all of its pieces and calculate the relative strength of a position.

  • In a calculator, the core would handle all of the numeric operators for the calculator.

Get hands-on with 1200+ tech skills courses.