-
-
Save NaeosPsy/d496bdbc882cf7b5fef480004d8c0924 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 Curry do | |
defmacro defc({name, ctx, arguments} = clause, do: expression) do | |
body = create_fun(arguments, expression) | |
quote do | |
def unquote(clause), do: unquote(expression) | |
def unquote({name, ctx, []}), do: unquote(body) | |
end | |
end | |
defp create_fun([h | t], expression) do | |
rest = create_fun(t, expression) | |
quote do | |
fn unquote(h) -> unquote(rest) end | |
end | |
end | |
defp create_fun([], expression) do | |
quote do | |
unquote(expression) | |
end | |
end | |
end | |
defmodule Example do | |
import Curry | |
defc sum(a, b), do: a + b | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment