Skip to content

Instantly share code, notes, and snippets.

@matteosister
Last active September 23, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteosister/4dd4e76515b86810a9f0 to your computer and use it in GitHub Desktop.
Save matteosister/4dd4e76515b86810a9f0 to your computer and use it in GitHub Desktop.
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