Refactoring is one of the important processes in software development.
This is an exploration of of code written in familiar imperative programming patterns, and refactored using a counterpart functional programming pattern. The goal is to build up a handy bidirectional map of corresponding imperative and functional patterns.
These patterns use Scala to take advantage of its hybrid object-oriented and functional design, which caters to both imperative and functional patterns.
We use Rúnar Bjarnason’s definition of referential transparency.
- an expression
eis referentially transparent if for all programs
p, every occurrence of
pcan be replaced with the result of evaluating
ewithout changing the result of evaluating
We use Martin Fowler’s definitions of refactoring.
- a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
- to restructure software by applying a series of refactorings without changing its observable behavior.
freewith a monad