Croma
Elixir macro utilities.
Usage
- Add
:cromaas a mix dependency. $ mix deps.get- Add
use Cromato import all macros defined in this package. - Hack!
Croma.Defpt.defpt
Unit-testable defp that is simply converted to
defifMix.env == :test,defpotherwise.
Croma.Defun
Type specification oriented function definition
Example 1
import Croma.Defundefun f(a: integer, b: String.t) :: String.t do"#{a} #{b}"end
is expanded to
ex @spec f(integer, String.t) :: String.t def f(a, b) do "#{a} #{b}" end
Example 2
import Croma.Defundefun dumbmap(as: [a], f: (a -> b)) :: [b] when a: term, b: term do([] , _) -> []([h | t], f) -> [f.(h) | dumbmap(t, f)]end
is expanded to
ex @spec dumbmap([a], (a -> b)) :: [b] when a: term, b: term def dumbmap(as, f) def dumbmap([], _) do [] end def dumbmap([h | t], f) do [f.(h) | dumbmap(t, f)] end
- There are also
defunpanddefunptmacros for private functions. - Known limitations:
- Pattern matching against function parameters should use
(param1, param2) when guards -> blockstyle. - Overloaded typespecs are not supported.
- Pattern matching against function parameters should use