Search⌘ K

Building Our Functional Core

Explore how to create a functional core in Elixir that isolates business logic from process management. Understand the importance of pure functions with no side effects and learn to implement a simple counter logic. This lesson helps you handle complexity in isolation, making your code easier to test and maintain within OTP projects.

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 ...