Syntactic v0.0.2 Syntactic

Provides some syntactic sugars

Summary

Macros

Expands to a keyword list with keys as atoms of given vars. For example keys([name, age]) expands to [name: name, age: age]

Expands to a Map with keys as atoms of given vars. For example map([name, age]) expands to %{name: name, age: age}

Expands to a Map with keys as strings of given vars. For example maps([name, age]) expands to %{"name" => name, "age" => age}

Macros

keys(keys)

Expands to a keyword list with keys as atoms of given vars. For example keys([name, age]) expands to [name: name, age: age]

Useful in matches:

def full_name(keys(first_name, last_name)) do
  first_name <> " " <> last_name
end

full_name(first_name: "Alan", last_name: "Parsons")
# => "Alan Parsons"
keys(a, b)
keys(a, b, c)
keys(a, b, c, d)
keys(a, b, c, d, e)
map(keys)

Expands to a Map with keys as atoms of given vars. For example map([name, age]) expands to %{name: name, age: age}

Useful in matches:

map(a, b) = %{a: 10, b: "Some Value"}
map(a, b)
map(a, b, c)
map(a, b, c, d)
map(a, b, c, d, e)
maps(keys)

Expands to a Map with keys as strings of given vars. For example maps([name, age]) expands to %{"name" => name, "age" => age}

maps(a, b)
maps(a, b, c)
maps(a, b, c, d)
maps(a, b, c, d, e)