{"id":31588622,"url":"https://github.com/bardoor/then","last_synced_at":"2025-10-06T02:12:05.078Z","repository":{"id":311813653,"uuid":"1044933213","full_name":"bardoor/then","owner":"bardoor","description":"Simple way to set after-function callback","archived":false,"fork":false,"pushed_at":"2025-08-26T23:43:47.000Z","size":50,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-11T22:07:27.184Z","etag":null,"topics":["aspect-oriented-programming","elixir","functional-programming"],"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/bardoor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-26T12:14:56.000Z","updated_at":"2025-08-27T07:29:49.000Z","dependencies_parsed_at":"2025-08-27T02:47:14.027Z","dependency_job_id":"578b02d8-af68-41ad-a063-168b8e95edb1","html_url":"https://github.com/bardoor/then","commit_stats":null,"previous_names":["bardoor/then"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bardoor/then","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bardoor%2Fthen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bardoor%2Fthen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bardoor%2Fthen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bardoor%2Fthen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bardoor","download_url":"https://codeload.github.com/bardoor/then/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bardoor%2Fthen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278547821,"owners_count":26004775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["aspect-oriented-programming","elixir","functional-programming"],"created_at":"2025-10-06T02:11:38.105Z","updated_at":"2025-10-06T02:12:05.072Z","avatar_url":"https://github.com/bardoor.png","language":"Elixir","readme":"# Then\n\n[![Elixir CI](https://github.com/bardoor/then/actions/workflows/elixir.yml/badge.svg)](https://github.com/bardoor/then/actions/workflows/elixir.yml)\n[![Hex.pm Version](https://img.shields.io/hexpm/v/then.svg)](https://hex.pm/packages/then)\n[![Hex.pm Downloads](https://img.shields.io/hexpm/dt/then.svg)](https://hex.pm/packages/then)\n[![Documentation](https://img.shields.io/badge/docs-hexdocs-blue.svg)](https://hexdocs.pm/then)\n\nBecause sometimes you want to do something *after* a function, but don't want to clutter its code.\n\nPut `@then :callback` or `@then {Module, :callback}` above a function and it will automatically \ncall the callback after execution. Function result stays unchanged, callback is called for side effects.\n\n## Installation\n\n```elixir\ndef deps do\n  [{:then, \"~\u003e 1.2.0\"}]\nend\n```\n\n## Basic Usage\n\n### Simple Local Callbacks\n\n```elixir\ndefmodule MyModule do\n  use Then\n\n  @then :log\n  def add(a, b) do\n    a + b\n  end\n\n  def log(result) do\n    IO.puts(\"Got #{result}\")\n  end\nend\n\nMyModule.add(2, 3)\n# Got 5\n# =\u003e 5\n```\n\n### External Module Callbacks\n\nYou can also call functions from other modules:\n\n```elixir\ndefmodule Calculator do\n  use Then\n\n  @then {IO, :puts}\n  def multiply(a, b) do\n    a * b\n  end\n\n  @then {MyAudit, :track_operation}\n  def divide(a, b) when b != 0 do\n    a / b\n  end\nend\n\ndefmodule MyAudit do\n  def track_operation(result) do\n    IO.puts(\"Operation completed with result: #{result}\")\n  end\nend\n```\n\n**Aliased modules work too:**\n\n```elixir\ndefmodule Calculator do\n  alias IO, as: MyIO\n  use Then\n\n  @then {MyIO, :puts}\n  def calculate(x) do\n    x * 2\n  end\nend\n```\n\n### Real-world Example\n\n```elixir\ndefmodule UserService do\n  use Then\n\n  @then :audit_creation\n  def new_user(params) do\n    case params do\n      %{email: email, name: name} -\u003e {:ok, %User{name: name, email: email}}\n      _ -\u003e {:error, \"Required fields are missing\"}\n    end\n  end\n\n  # side effects separately\n  def audit_creation({:ok, user}), do: IO.puts(\"✅ User #{user.email} created\")\n  def audit_creation({:error, reason}), do: IO.puts(\"❌ User creation failed: #{reason}\")\nend\n```\n\n### Compatibility\n\nWorks perfectly with other function attributes:\n\n```elixir\ndefmodule MyService do\n  use Then\n\n  @doc \"Gets age from params\"\n  @spec get_age(map()) :: integer()\n  @then :log_term\n  def get_age(params) do\n    params[:age] || 0\n  end\n\n  defp log_term(term), do: IO.puts(\"[log-term] #{term}\")\nend\n```\n\n`@spec`, `@doc`, `@deprecated` and other attributes work as expected.\nCallback functions can be private (`defp`).\n\n### Limitations\n\n- One `@then` per function (compilation error if you try to use multiple)\n- Callback is not called if function raises an exception\n- For functions with multiple clauses, `@then` applies to all clauses\n- External module callbacks must be available at compile time\n\n### Callback Formats\n\n`@then` accepts two formats:\n- `:function_name` - calls local function\n- `{ModuleName, :function_name}` - calls function from external module\n\n### Why Use This?\n\nIt's simple and clear. Move log and other side-effects out of your b","funding_links":[],"categories":["Macros"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbardoor%2Fthen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbardoor%2Fthen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbardoor%2Fthen/lists"}