Last active
September 23, 2015 22:00
-
-
Save matteosister/4dd4e76515b86810a9f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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