anaphora alternatives and similar packages
Based on the "Macros" category.
Alternatively, view anaphora alternatives based on common mentions on social networks and blogs.
-
typed_struct
An Elixir library for defining structs with a type without writing boilerplate code. -
shorter_maps
Elixir ~M sigil for map shorthand. `~M{id, name} ~> %{id: id, name: name}` -
eventsourced
Functional domain models with event sourcing in Elixir -
ok_jose
Pipe elixir functions that match ok/error tuples or custom patterns. -
crudry
Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers. -
pipe_to
The enhanced elixir pipe operator which can specify the target position -
pattern_tap
Macro for tapping into a pattern match while using the pipe operator -
pipe_here
An Elixir macro for easily piping arguments at any position. -
guardsafe
Macros expanding into code that can be safely used in guard clauses. -
rulex
This tiny library (2 macros only) allows you to define very simple rule handler using Elixir pattern matching. -
apix
Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation. -
Bang
Bang simply adds dynamic bang! functions to your existing module functions with after-callback. -
backports
Ensure backwards compatibility even if newer functions are used
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of anaphora or a related project?
Popular Comparisons
README
Anaphora

Anaphora
is the anaphoric macro collection for Elixir. An anaphoric macro is one that deliberately captures a variable (typically it
) from forms supplied to the macro.
Getting Started
- Add the
Anaphora
dependency to yourmix.exs
file:
def deps do
[{:anaphora, "~> 0.1.2"}]
end
- After you are done, run
mix deps.get
in your shell.
Provided API
alet
alet
is basic anaphoric macro. It's not very useful in user code but other anaphoric macros are built on top of it. alet
binds result of the expression to the it
variable (via case
) in the scope of the body:
defmodule User do
use Anaphora
...
def user_email(user_id) do
alet fetch_user(user_id) do
if it, do: it.email, else: raise "Failed to fetch user"
end
end
end
aif
Works like if
, except that result of the condition is bound to it
(via alet
) for the scope of the then and else clauses:
defmodule User do
use Anaphora
...
def user_email(user_id) do
aif fetch_user(user_id), do: it.email, else: raise "Failed to fetch user"
end
end
acond
Works like cond
, except that result of each condition is bound to it
(via alet
) for the scope of the corresponding body:
defmodule Notification do
use Anaphora
...
def send_notification(user, message) do
acond do
user.email -> send_notification_by_email(it, message)
user.phone -> send_notification_by_sms(it, message)
:else -> raise "Unable to send notification"
end
end
end
acase
Works like case
, except that result of the key expression is bound to it
(via alet
) for the scope of the cases.
afn
Works like fn
, except that anonymous function is bound to it
(via blood magic
) for the scope of the function body:
import Anaphora
in_order_tree_traversal = afn do
{left, center, right}, callback ->
it.(left, callback)
callback.(center)
it.(right, callback)
nil, _ -> nil
end
in_order_tree_traversal.({{nil, 1, nil}, 2, {nil, 3, {nil, 4, nil}}}, &IO.puts/1)
# => 1, 2, 3, 4
warning: Invocation of it
takes a lot of time. Don't use afn
in performance critical code. It will be fixed after Elixir 1.0
release.
aand
Evaluates each clause one at a time and binds result to it
. As soon as any clause evaluates to nil
(or false
), aand
returns nil
without evaluating the remaining clauses. If all clauses but the last evaluate to true values, aand
returns the results produced by evaluating the last clause:
defmodule Notification do
use Anaphora
...
def send_email_to_user(user_id, message) do
aand do
fetch_user(user_id)
it.email
send_email(it, message)
end || raise "Unable to send email"
end
end
License
Anaphora source code is released under The MIT License. Check LICENSE file for more information.
*Note that all licence references and agreements mentioned in the anaphora README section above
are relevant to that project's source code only.