Last active
August 29, 2015 14:10
-
-
Save bltavares/6984d49089e193a6181b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Challenge do | |
def printer("", acc) do | |
acc | |
end | |
def printer("%%d" <> rest, acc) do | |
fn int -> | |
next = acc <> to_string(int) | |
printer(rest, next) | |
end | |
end | |
def printer("%%s" <> rest, acc) do | |
fn str -> | |
printer(rest, acc <> str) | |
end | |
end | |
def printer(expr, acc) do | |
[h| t] = String.codepoints(expr) | |
printer(to_string(t), acc <> h) | |
end | |
def printf(str) do | |
printer(str, "") | |
end | |
end | |
Challenge.printf("hello %%d %%s").(1).("world") |> IO.puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment