elixir

Resources

TDD

Using ExUnit: mix test --stale --max-failures 1 --listen-on-stdin --trace --seed 0

Recommended deps

Notes

Data Types

Data Structures

Tuples: {"any", "type", 1, false}

List: ["here", "too", 123, true]

Charlist: ['a', 'b', 'c'] = 'abc'

Maps: %{"any" => :value, 123 => true, "keys" => :too}

Keywords: ?

Structs: ?

Control Flow

Functions

Modules

Like Classes

Typespec and Doc

Create new type and assign it to spec:

@type address_map() :: %{street: String.t(), postal_code: String.t(), city: String.t()}
@type address_tuple() :: {street :: String.t(), postal_code :: String.t(), city :: String.t()}
@type address() :: address_map() | address_tuple()

@doc """
Formats the address as an uppercase multiline string.
"""
@spec format_address(address()) :: String.t()
def format_address(%{street: street, postal_code: postal_code, city: city}) do
  format_address({street, postal_code, city})
end

def format_address({street, postal_code, city}) do
  """
  #{String.upcase(street)}
  #{String.upcase(postal_code)} #{String.upcase(city)}
  """
end

List of types: Typespecs