Recap
In this appendix, we looked at the origins of functional programming and its mathematical foundations. Then we discussed the benefits of adopting it in our code.
From mathematical foundations, we have derived three functional principles for writing code:
-
Purity: The same inputs always produce the same results.
-
Immutability: All data structures are immutable.
-
Totality: Functions return a result for any input, without throwing exceptions.
We have also derived four heuristic rules:
-
Prefer a declarative style. Express what you want to achieve with your code rather than the how.
-
Define your types precisely. Make the signature of your function meaningful.
-
Treat functions as data. Define behavior combining simpler functions together.
-
Try to be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access