Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

|>

Slide 3

Slide 3 text

Treat.give(Dog.find(dog_id)) dog_id |> Dog.find() |> Treat.give()

Slide 4

Slide 4 text

new_email( to: "foo@example.com", from: "me@example.com", subject: "Welcome!!!", html_body: "Welcome", text_body: "welcome" )

Slide 5

Slide 5 text

new_email |> to("foo@example.com") |> from("me@example.com") |> subject("Welcome!!!") |> html_body("Welcome") |> text_body("welcome")

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

x = 1 # this is the "match" operator 1 = x # this is completely legit # lists [a, b, c] = [1, 2, 3] # maps %{id: id} = %{id: 1} %{id: id} = %{id: 1, name: "fido"} %{id: id} = %User{id: 1} # structs work too! # tuples {:ok, status, response} = {:ok, 200, "

Dogs

"}

Slide 8

Slide 8 text

{:ok, response} = HTTP.get("/dogs")

Slide 9

Slide 9 text

case HTTP.get("/dogs") do {:ok, response} -> Logger.info(response) {:error, error} -> Logger.error(error) end

Slide 10

Slide 10 text

defmodule DogService do def run do HTTP.get("/doggies") end def log({:ok, response}) do Logger.info(response) end def log({:error, error}) do Logger.error(error) end def log(_) do Logger.error("uhh... what happened?") end end DogService.run |> DogService.log

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

def give_treat(dog) do if dog do if dog.age > 5 "here ya go, #{dog.name}" else "here ya go, pup" end else "uhhh... no dog?" end end

Slide 13

Slide 13 text

def give_treat(nil), do: "uhh... no dog?" def give_treat(%{name: name, id: id}) when id > 5 do "here ya go, #{name}" end def give_treat(_) do "here ya go, pup" end

Slide 14

Slide 14 text

def give_treat(nil), do: "uhh... no dog?" def give_treat(id) when is_integer(id) do id |> find |> give_treat end def give_treat(%{age: age, name: name}) when age > 5 do "here ya go, #{name}" end def give_treat(_) do "here ya go, pup" end

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

case DB.insert(changeset) do {:ok, record} -> # woot woot! {:error, :timeout} -> # handle it {:error, changeset} -> # handle it end

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

def save(changeset) do case DB.insert(changeset) do {:ok, record} -> case ElasticSearch.sync(record) do {:ok, _, response} -> {:ok, record, response} {:error, status, response} -> {:error, status, response} end {:error, error} -> {:error, error} end end

Slide 19

Slide 19 text

with {:ok, record} <- DB.insert(changeset), {:ok, _, response} <- ElasticSearch.sync(record), do: {:ok, record, response}

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

iex> quote do: sum(1, 2, 3) {:sum, [], [1, 2, 3]}

Slide 22

Slide 22 text

iex> Macro.to_string(quote do: sum(1, 2 + 3, 4)) "sum(1, 2 + 3, 4)"

Slide 23

Slide 23 text

iex> number = 13 iex> Macro.to_string(quote do: 11 + number) "11 + number" iex> number = 13 iex> Macro.to_string(quote do: 11 + unquote(number)) "11 + 13"

Slide 24

Slide 24 text

assert "foo" =~ "bar" Assertion with =~ failed code: "foo" =~ "bar" lhs: "foo" rhs: "bar"

Slide 25

Slide 25 text

defmodule Example do def iif(test, a, b) do if test, do: a, else: b end end Example.iif(false, IO.puts("a"), IO.puts("b")) Example.iif(true, IO.puts("a"), IO.puts("b"))

Slide 26

Slide 26 text

a b a b

Slide 27

Slide 27 text

defmodule Example do defmacro iif(test, a, b) do quote do if unquote(test), do: unquote(a), else: unquote(b) end end end Example.iif(false, IO.puts("a"), IO.puts("b")) Example.iif(true, IO.puts("a"), IO.puts("b"))

Slide 28

Slide 28 text

b a

Slide 29

Slide 29 text

from fish in Fish, join: fisherman in assoc(fish, :fisherman), group_by: fisherman.name, select: [max(fish.length), fisherman.name]