Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
defmodule PipeFunctionComposition do
require Integer
def even(n), do: Integer.is_even(n)
def negate(n), do: not n
def multiply_by(n, factor), do: n * factor
@doc """
true if the passed number is not even
"""
def not_even(n) do
n
|> even
|> negate
end
@doc """
true if the given number, multiplied by a factor, is even
"""
def is_even_multiplied_by(n, factor) do
n
|> multiply_by(factor)
|> even
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment