elixir-idioms
irahardianto/awesome-agv/.agents/skills/elixir-idioms/SKILL.md
Elixir and OTP idioms: pattern matching, `with` pipelines, GenServer and supervision tree architecture, fault-tolerant concurrency, and ExUnit testing. Use when developing, refactoring, or reviewing Elixir and Phoenix applications or OTP systems.
Skill157 starsChanged 43 days ago
What's in it
- Elixir Idioms and Patterns
- Pattern Matching
- OTP and Supervision
- Pipe Operator
- Naming
- Testing
- Formatting and Static Analysis
- Related
---
name: elixir-idioms
description: >-
Elixir and OTP idioms: pattern matching, `with` pipelines, GenServer and supervision tree architecture, fault-tolerant concurrency, and ExUnit testing. Use when developing, refactoring, or reviewing Elixir and Phoenix applications or OTP systems.
---
## Elixir Idioms and Patterns
Elixir rewards immutability, pattern matching, and the OTP supervision model. Idiomatic Elixir = functional, fault-tolerant, process-oriented.
> Scope: Elixir coding idioms. Test naming: .agents/rules/testing-strategy.md.
### Pattern Matching
1. **Pattern match everything — function heads, case, with:**
```elixir
def handle_result({:ok, task}), do: {:reply, task}
def handle_result({:error, :not_found}), do: {:error, 404}
def handle_result({:error, reason}), do: {:error, 500, reason}
```
2. **`with` for happy-path pipelines:**
```elixir
with {:ok, user} <- fetch_user(user_id),
{:ok, task} <- create_task(user, params),
:ok <- notify(user, task) do
{:ok, task}
end
```
### OTP and Supervision
1. **GenServer for stateful processes:**
```elixir
defmodule TaskCache do
use GenServer
def start_link(opts), do: GenServer.start_link(__MODULE__, %{}, opts)
def get(pid, id), do: GenServer.call(pid, {:get, id})
@impl true
def handle_call({:get, id}, _from, state) do
{:reply, Map.get(state, id), state}
end
end
```
2. **Supervision trees — "let it crash" philosophy.** Supervisors restart failed children.
3. **Never `try/catch` in normal flow** — let processes crash and restart cleanly.
### Pipe Operator
1. **`|>` for data transformation pipelines:**
```elixir
tasks
|> Enum.filter(&(&1.active))
|> Enum.sort_by(& &1.priority, :desc)
|> Enum.map(&TaskView.render/1)
```
2. **First argument must be the piped value.** Design APIs pipe-friendly.
### Naming
1. **snake_case** for functions, variables, atoms, module attributes.
2. **PascalCase** for module names.
3. **`?` suffix** for boolean functions: `active?/1`.
4. **`!` suffix** for functions that raise: `get!/1` (vs `get/1` returning `{:ok, _}`).
### Testing
1. **ExUnit:**
```elixir
defmodule TaskServiceTest do
use ExUnit.Case, async: true
test "creates task with valid params" do
{:ok, task} = TaskService.create(%{title: "Test", priority: :high})
assert task.title == "Test"
end
end
```
2. **Mox for mock-based testing** (behaviour contracts).
### Formatting and Static Analysis
| Tool | Purpose | Command |
|---|---|---|
| `mix format` | Formatting | `mix format` |
| Credo | Linting | `mix credo --strict` |
| Dialyzer | Type checking | `mix dialyzer` |
| `mix deps.audit` | CVE scanning | `mix deps.audit` |
### Related
- Code Idioms and Conventions .agents/rules/code-idioms-and-conventions.md
- Error Handling Principles .agents/rules/error-handling-principles.md
- Testing Strategy .agents/rules/testing-strategy.md
- Concurrency and Threading Principles @.agents/rules/concurrency-and-threading-principles.md
More agent context in irahardianto/awesome-agv
59 other files this repository gives its agents.
AGENTS.md
Skill
- adr.agents/skills/adr/SKILL.md
- agent-protocols.agents/skills/agent-protocols/SKILL.md
- angular-idioms.agents/skills/angular-idioms/SKILL.md
- api-documentation.agents/skills/api-documentation/SKILL.md
- axum-idioms.agents/skills/axum-idioms/SKILL.md
- browser-automation.agents/skills/browser-automation/SKILL.md
- chaos-testing.agents/skills/chaos-testing/SKILL.md
- ci-cd.agents/skills/ci-cd/SKILL.md
- cli-development.agents/skills/cli-development/SKILL.md
- code-audit.agents/skills/code-audit/SKILL.md
- code-review.agents/skills/code-review/SKILL.md
- cpp-idioms.agents/skills/cpp-idioms/SKILL.md
- csharp-idioms.agents/skills/csharp-idioms/SKILL.md
- data-engineering.agents/skills/data-engineering/SKILL.md
- debugging-protocol.agents/skills/debugging-protocol/SKILL.md
- django-idioms.agents/skills/django-idioms/SKILL.md
- dotnet-idioms.agents/skills/dotnet-idioms/SKILL.md
- embedded-systems.agents/skills/embedded-systems/SKILL.md
- feature-flags.agents/skills/feature-flags/SKILL.md
- flutter-idioms.agents/skills/flutter-idioms/SKILL.md
- frontend-design.agents/skills/frontend-design/SKILL.md
- git-commit-integrity.agents/skills/git-commit-integrity/SKILL.md
- go-idioms.agents/skills/go-idioms/SKILL.md
- guardrails.agents/skills/guardrails/SKILL.md
- hono-idioms.agents/skills/hono-idioms/SKILL.md
- incident-response.agents/skills/incident-response/SKILL.md
- java-idioms.agents/skills/java-idioms/SKILL.md
- javascript-idioms.agents/skills/javascript-idioms/SKILL.md
- kotlin-idioms.agents/skills/kotlin-idioms/SKILL.md
- laravel-idioms.agents/skills/laravel-idioms/SKILL.md
- logging-implementation.agents/skills/logging-implementation/SKILL.md
- ml-engineering.agents/skills/ml-engineering/SKILL.md
- mobile-design.agents/skills/mobile-design/SKILL.md
- mobile-testing.agents/skills/mobile-testing/SKILL.md
- nextjs-idioms.agents/skills/nextjs-idioms/SKILL.md
- parallel-dispatch.agents/skills/parallel-dispatch/SKILL.md
- payment-integration.agents/skills/payment-integration/SKILL.md
- perf-optimization.agents/skills/perf-optimization/SKILL.md
- php-idioms.agents/skills/php-idioms/SKILL.md
- postgres-idioms.agents/skills/postgres-idioms/SKILL.md
- python-idioms.agents/skills/python-idioms/SKILL.md
- rails-idioms.agents/skills/rails-idioms/SKILL.md
- react-idioms.agents/skills/react-idioms/SKILL.md
- refactoring-patterns.agents/skills/refactoring-patterns/SKILL.md
- research-methodology.agents/skills/research-methodology/SKILL.md
- ruby-idioms.agents/skills/ruby-idioms/SKILL.md
- rust-idioms.agents/skills/rust-idioms/SKILL.md
- security-audit.agents/skills/security-audit/SKILL.md
- sequential-thinking.agents/skills/sequential-thinking/SKILL.md
- spring-boot-idioms.agents/skills/spring-boot-idioms/SKILL.md
- sql-idioms.agents/skills/sql-idioms/SKILL.md
- structured-spec.agents/skills/structured-spec/SKILL.md
- supply-chain-security.agents/skills/supply-chain-security/SKILL.md
- swift-idioms.agents/skills/swift-idioms/SKILL.md
- testability-patterns.agents/skills/testability-patterns/SKILL.md
- testing-strategy.agents/skills/testing-strategy/SKILL.md
- typescript-idioms.agents/skills/typescript-idioms/SKILL.md
- vue-idioms.agents/skills/vue-idioms/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

