elixir-phoenix-elixir-idioms
Apply Elixir and OTP idioms for processes, tasks, registries, and control flow.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Apply Elixir and OTP idioms for processes, tasks, registries, and control flow.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Recommend the right `$elixir-phoenix-*` skill for the current task.
Elixir/Phoenix: Review lifecycle, state-machine, Oban, persistence, pause/resume, retry, and restart-sensitive changes before commit, push, or PR. Use for concurrency-sensitive runtime work to produce explicit blocking vs optional findings, require durability checks, and verify smoke plus restart resilience when applicable.
Capture a solved Phoenix problem as a reusable solution doc.
Audit LiveView assigns for memory bloat, dead assigns, and stream candidates.
Audit project health across architecture, security, performance, tests, and deps.
Analyze Phoenix context boundaries and coupling with `mix xref`.
| name | elixir-phoenix-elixir-idioms |
| description | Apply Elixir and OTP idioms for processes, tasks, registries, and control flow. |
| metadata | {"short-description":"Apply Elixir and OTP idioms"} |
Reference for writing idiomatic Elixir code with BEAM-aware patterns.
and/or/not — Never use short-circuit operators in guards (guards require boolean operands)cast/4 for user input, change/2 for internalString.to_atom(user_input) causes memory leak (atoms aren't GC'd)@external_resourceGenServer.start_link/Agent.start_link in production. Use supervision treescase, then cond{:ok, _}/{:error, _} for expected errors, raise for bugsNeed patterns? → case (or function heads)
Multiple operations? → with
Boolean conditions? → cond (multiple) or if (single)
Expected failure? → {:ok, _}/{:error, _} tuples
Unexpected/bug? → raise exception (let supervisor handle)
External library? → rescue (only here!)
Need state?
├─ No → Plain functions
├─ Simple get/update → Agent or ETS
├─ Complex messages/timeouts → GenServer
└─ One-off async → Task
# Pattern match in function head
def process(%{status: :active} = user), do: activate(user)
def process(%{status: :inactive} = user), do: deactivate(user)
# with for happy path
with {:ok, user} <- get_user(id),
{:ok, order} <- create_order(user) do
{:ok, order}
end
# Task for async
Task.Supervisor.async_nolink(TaskSup, fn -> work() end)
|> Task.yield(5000) || Task.shutdown(task)
| Wrong | Right |
|---|---|
length(list) == 0 | list == [] or Enum.empty?(list) |
list ++ [item] | [item | list] |> Enum.reverse() |
String.to_atom(input) | String.to_existing_atom(input) |
spawn(fn -> log(conn) end) | ip = conn.ip; spawn(fn -> log(ip) end) |
unless condition | if !condition (unless deprecated in 1.18) |
For detailed patterns, see:
references/pattern-matching.md - Pattern matching, guards, binary matchingreferences/otp-patterns.md - GenServer, Supervisor, Task, Registryreferences/error-handling.md - Tagged tuples, rescue, withreferences/with-and-pipes.md - When to use with and |> (idiomatic patterns)references/troubleshooting.md - Production BEAM debugging (memory, performance, crashes)references/anti-patterns.md - Common mistakes and fixesreferences/mix-tasks.md - Mix task naming, option parsing, shell outputreferences/elixir-118-features.md - Duration module, dbg improvements (1.18+)