A pure function is a method or function in functional programming that does not affect the state of the program. This means that a pure function cannot be used to mutate or change variables or objects declared in the program. A pure function also does not interact with the I/O. Its output is also deterministic.
iex> sum = &(&1 + &2 + &3)iex> sum.(10, 3 , 5)#Output = 18iex> sum.(14, 2 , 1)#Output = 17iex> sum.(2, 1 , 5)#Output = 8iex> sum.(10, None , 5)#Output = Erroriex> sum.(None, 3 , 5)#Output = Error
You can try using the function in the terminal below :
Line 1: We create a function that calculates the sum of all three parameters’ values.
Line 3–15: We call the sum
function and try it with different parameter values.
Free Resources