Skip to content

Instantly share code, notes, and snippets.

@NaeosPsy
Created May 20, 2021 20:17
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 NaeosPsy/d496bdbc882cf7b5fef480004d8c0924 to your computer and use it in GitHub Desktop.
Save NaeosPsy/d496bdbc882cf7b5fef480004d8c0924 to your computer and use it in GitHub Desktop.
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