Created
December 21, 2016 23:04
-
-
Save fk1blow/a6dc01fa1cbd277390e0fda6b913f873 to your computer and use it in GitHub Desktop.
i have not idea what is going on
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 Dobar.Effect do | |
| alias Dobar.Error | |
| alias Dobar.Reaction | |
| @type t :: %__MODULE__{ | |
| reaction: Reaction.t, | |
| error: Error.EvaluationError.t | nil, | |
| responders: [...], | |
| robot: binary | atom | |
| } | |
| defstruct reaction: %Dobar.Reaction{}, | |
| error: nil, | |
| responders: [], | |
| robot: :undefined_waka | |
| defmacro __using__(_) do | |
| quote do | |
| import Dobar.Effect | |
| @before_compile Dobar.Effect | |
| end | |
| end | |
| defmacro on(message, do: block) do | |
| quote do | |
| def handle_on(unquote(message), var!(interface)), do: fn -> unquote(block) end | |
| end | |
| end | |
| defmacro on(message) do | |
| raise "You cannot declare an effect that does 'nothing'" | |
| end | |
| defmacro __before_compile__(_env) do | |
| quote do | |
| # catch non-matches to avoid runtime errors | |
| def handle_on(_, _), do: nil | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment