-
-
Save josevalim/ea084b59f88de1ab6d35 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 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