Catalog / Elixir Cheatsheet
Elixir Cheatsheet
A concise reference for Elixir syntax, data structures, and common functions.
Basics & Syntax
Basic Syntax
Variable Assignment |
Elixir is immutable, so variables can only be bound once. |
Atoms |
Atoms are constants whose value is their name.
|
Modules |
|
Anonymous Functions |
Can be assigned to variables: |
Comments |
|
Pipe Operator |
Chains function calls, passing the result of the previous function as the first argument to the next. |
Data Types
Integers |
|
Floats |
|
Booleans |
|
Strings |
|
Lists |
|
Tuples |
|
Data Structures
Lists
Creating Lists |
|
List Concatenation |
|
List Subtraction |
|
Head and Tail |
|
Accessing Elements |
Lists are not designed for random access. |
Tuples
Creating Tuples |
|
Accessing Elements |
|
Tuple Size |
|
Use Cases |
Often used to return multiple values from a function, especially for error handling. |
Maps
Creating Maps |
|
Accessing Values |
|
Updating Values |
|
Adding Values |
|
Removing Values |
|
Control Flow
Conditional Statements
|
|
|
|
|
|
Case Statement
Basic Usage |
|
Pattern Matching |
|
Guards |
|
Enum Module
|
Applies a function to each element in a collection and returns a new collection with the results.
|
|
Filters elements from a collection based on a given function.
|
|
Reduces a collection to a single value by applying a function cumulatively.
|
|
Iterates over a collection and applies a function to each element (for side effects).
|
Concurrency & OTP
Processes
Spawning Processes |
Creates a new lightweight process. |
Sending Messages |
Sends a message to a process identified by its PID. |
Receiving Messages |
|
GenServer
Defining a GenServer |
|
Starting a GenServer |
|
|
Handles synchronous requests.
|
|
Handles asynchronous requests.
|
|
Handles other messages.
|
Supervisors
Defining a Supervisor |
|
Supervision Strategies |
|