Last active
December 24, 2017 05:09
-
-
Save dwhelan/5651de36bfee7ad6c8720c981b5bfc0f to your computer and use it in GitHub Desktop.
If you have a name with "la" in it, allows you to Elixirify your name where your name can be represented with valid pipelined Elixir functions. For example, if your name is "declan" then dec|>n returns "declan").
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
iex> c "lib/name.ex" | |
[MyName, ElixirName] | |
iex> MyName.is | |
"declan |
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 ElixirName do | |
defmacro __using__(name) do | |
[prefix, suffix] = String.split(name, "la") | |
quote do | |
import unquote(__MODULE__) | |
def unquote(:"#{prefix}")(), do: unquote(prefix) | |
def unquote(:"#{suffix}")(x), do: "#{x}la#{unquote(suffix)}" | |
end | |
end | |
end | |
defmodule MyName do | |
use ElixirName, "declan" | |
def is do | |
dec|>n | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment