{"id":13508515,"url":"https://github.com/sviridov/anaphora-elixir","last_synced_at":"2026-02-22T19:01:57.217Z","repository":{"id":19988701,"uuid":"23255926","full_name":"sviridov/anaphora-elixir","owner":"sviridov","description":"The anaphoric macro collection for Elixir","archived":false,"fork":false,"pushed_at":"2016-02-24T05:54:16.000Z","size":17,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T14:52:01.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sviridov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-23T13:04:31.000Z","updated_at":"2024-01-26T13:30:34.000Z","dependencies_parsed_at":"2022-07-22T03:31:59.314Z","dependency_job_id":null,"html_url":"https://github.com/sviridov/anaphora-elixir","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sviridov/anaphora-elixir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviridov%2Fanaphora-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviridov%2Fanaphora-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviridov%2Fanaphora-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviridov%2Fanaphora-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sviridov","download_url":"https://codeload.github.com/sviridov/anaphora-elixir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sviridov%2Fanaphora-elixir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29723573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:54.207Z","updated_at":"2026-02-22T19:01:57.181Z","avatar_url":"https://github.com/sviridov.png","language":"Elixir","funding_links":[],"categories":["Macros"],"sub_categories":[],"readme":"## Anaphora [![Build Status](https://travis-ci.org/sviridov/anaphora-elixir.svg)](https://travis-ci.org/sviridov/anaphora-elixir) [![license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/sviridov/anaphora-elixir/blob/master/LICENSE) [![hex.pm](http://img.shields.io/badge/hex.pm-0.1.2-brightgreen.svg)](https://hex.pm/packages/anaphora)\n\n`Anaphora` is the anaphoric macro collection for [Elixir](https://github.com/elixir-lang/elixir/). An anaphoric macro is one that deliberately captures a variable (typically `it`) from forms supplied to the macro.\n\n### Getting Started\n\n - Add the `Anaphora` dependency to your `mix.exs` file:\n\n```elixir\ndef deps do\n  [{:anaphora, \"~\u003e 0.1.2\"}]\nend\n```\n\n - After you are done, run `mix deps.get` in your shell.\n\n### Provided API\n\n#### alet\n\n`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:\n\n```elixir\ndefmodule User do\n  use Anaphora\n\n  ...\n  def user_email(user_id) do\n    alet fetch_user(user_id) do\n      if it, do: it.email, else: raise \"Failed to fetch user\"\n    end\n  end\nend\n```\n\n#### aif\n\nWorks like `if`, except that result of the condition is bound to `it` (via `alet`) for the scope of the then and else clauses:\n\n```elixir\ndefmodule User do\n  use Anaphora\n\n  ...\n  def user_email(user_id) do\n    aif fetch_user(user_id), do: it.email, else: raise \"Failed to fetch user\"\n  end\nend\n```\n\n#### acond\n\nWorks like `cond`, except that result of each condition is bound to `it` (via `alet`) for the scope of the corresponding body:\n\n```elixir\ndefmodule Notification do\n  use Anaphora\n\n  ...\n  def send_notification(user, message) do\n    acond do\n      user.email -\u003e send_notification_by_email(it, message)\n      user.phone -\u003e send_notification_by_sms(it, message)\n      :else -\u003e raise \"Unable to send notification\"\n    end\n  end\nend\n```\n\n#### acase\n\nWorks like `case`, except that result of the key expression is bound to `it` (via `alet`) for the  scope of the cases.\n\n#### afn\n\nWorks like `fn`, except that anonymous function is bound to `it` (via `blood magic`) for the scope of the function  body:\n\n```elixir\nimport Anaphora\n\nin_order_tree_traversal = afn do\n  {left, center, right}, callback -\u003e\n    it.(left, callback)\n    callback.(center)\n    it.(right, callback)\n  nil, _ -\u003e nil\nend\n\nin_order_tree_traversal.({{nil, 1, nil}, 2, {nil, 3, {nil, 4, nil}}}, \u0026IO.puts/1)\n# =\u003e 1, 2, 3, 4\n```\n\n**warning:** Invocation of `it` takes a lot of time. Don't use `afn` in performance critical code. It will be fixed after [Elixir](https://github.com/elixir-lang/elixir/) `1.0` release.\n\n#### aand\n\nEvaluates 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:\n\n```elixir\ndefmodule Notification do\n  use Anaphora\n\n  ...\n  def send_email_to_user(user_id, message) do\n    aand do\n      fetch_user(user_id)\n      it.email\n      send_email(it, message)\n    end || raise \"Unable to send email\"\n  end\nend\n```\n\n### License\n\nAnaphora source code is released under The MIT License. Check LICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsviridov%2Fanaphora-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsviridov%2Fanaphora-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsviridov%2Fanaphora-elixir/lists"}