CRC Pattern - Construct - Reduce - Convert
The Answer
42
Functional Core
defmodule Counter do
# Construct
def new(input) do
String.to_integer(input)
end
# Reduce
def add(acc, number) do
acc + number
end
# Convert
def show(acc) do
"The ants arrrrrr be #{acc}"
end
end
Pipe
input = "42"
import Counter
input
|> new()
|> add(1)
|> add(1)
|> add(-1)
|> show()