Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created December 16, 2013 17:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josevalim/ea084b59f88de1ab6d35 to your computer and use it in GitHub Desktop.
Save josevalim/ea084b59f88de1ab6d35 to your computer and use it in GitHub Desktop.
defmodule Adapt do
@doc """
iex> myfun = fn(args) -> args end
iex> myfun3 = Adapt.adapt(myfun, 3)
iex> myfun3.(:a, :b, :c)
[:a, :b, :c]
iex> myfun2 = Adapt.adapt(myfun, 2)
iex> myfun2.(:x, :y)
[:x, :y]
"""
def adapt(fun, arity)
Enum.reduce(1..20, [], fn i, args ->
args = [{ :"arg#{i}", [], nil }|args]
def adapt(fun, unquote(i)) do
fn unquote_splicing(args) -> fun.(unquote(args)) end
end
args
end)
end
ExUnit.start
defmodule AdaptCase do
use ExUnit.Case
doctest Adapt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment