SlideShare a Scribd company logo
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
 |> 
Treat.give(Dog.find(dog_id))
dog_id
|> Dog.find()
|> Treat.give()
new_email(
to: "foo@example.com",
from: "me@example.com",
subject: "Welcome!!!",
html_body: "<strong>Welcome</strong>",
text_body: "welcome"
)
new_email
|> to("foo@example.com")
|> from("me@example.com")
|> subject("Welcome!!!")
|> html_body("<strong>Welcome</strong>")
|> text_body("welcome")
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
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, "<h1>Dogs</h1>"}
{:ok, response} = HTTP.get("/dogs")
case HTTP.get("/dogs") do
{:ok, response} ->
Logger.info(response)
{:error, error} ->
Logger.error(error)
end
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
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
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
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
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
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
case DB.insert(changeset) do
{:ok, record} ->
# woot woot!
{:error, :timeout} ->
# handle it
{:error, changeset} ->
# handle it
end
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
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
with {:ok, record} <- DB.insert(changeset),
{:ok, _, response} <- ElasticSearch.sync(record),
do: {:ok, record, response}
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
iex> quote do: sum(1, 2, 3)
{:sum, [], [1, 2, 3]}
iex> Macro.to_string(quote do: sum(1, 2 + 3, 4))
"sum(1, 2 + 3, 4)"
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"
assert "foo" =~ "bar"
Assertion with =~ failed
code: "foo" =~ "bar"
lhs: "foo"
rhs: "bar"
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"))
a
b
a
b
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"))
b
a
from fish in Fish,
join: fisherman in assoc(fish, :fisherman),
group_by: fisherman.name,
select: [max(fish.length), fisherman.name]

More Related Content

What's hot (20)

PDF
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
Педагошко друштво информатичара Србије
 
PDF
轻量级文本工具集
March Liu
 
PDF
The Chain Rule, Part 2
Pablo Antuna
 
PPTX
Python chapter 2
Raghu nath
 
PPTX
python chapter 1
Raghu nath
 
PPT
Knockout
LearningTech
 
PDF
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Yury Chemerkin
 
PDF
PyLecture4 -Python Basics2-
Yoshiki Satotani
 
KEY
Ruby nooks & crannies
Kerry Buckley
 
TXT
Manage catalog Configueation In Sharepoint PowerShell
Chitexe Marcos Maniche
 
PDF
2 BytesC++ course_2014_c2_ flow of control
kinan keshkeh
 
PDF
{:from => 'Java', :to => 'Ruby'}
Shintaro Kakutani
 
PDF
groovy databases
Paul King
 
PPTX
Database performance 101
Leon Fayer
 
PDF
Palestra sobre Collections com Python
pugpe
 
PDF
Let’s Talk About Ruby
Ian Bishop
 
PDF
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Plotly
 
PDF
kan r_ifels
皓丞 王
 
PDF
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
PPTX
PHP performance 101: so you need to use a database
Leon Fayer
 
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
Педагошко друштво информатичара Србије
 
轻量级文本工具集
March Liu
 
The Chain Rule, Part 2
Pablo Antuna
 
Python chapter 2
Raghu nath
 
python chapter 1
Raghu nath
 
Knockout
LearningTech
 
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Yury Chemerkin
 
PyLecture4 -Python Basics2-
Yoshiki Satotani
 
Ruby nooks & crannies
Kerry Buckley
 
Manage catalog Configueation In Sharepoint PowerShell
Chitexe Marcos Maniche
 
2 BytesC++ course_2014_c2_ flow of control
kinan keshkeh
 
{:from => 'Java', :to => 'Ruby'}
Shintaro Kakutani
 
groovy databases
Paul King
 
Database performance 101
Leon Fayer
 
Palestra sobre Collections com Python
pugpe
 
Let’s Talk About Ruby
Ian Bishop
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Plotly
 
kan r_ifels
皓丞 王
 
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
PHP performance 101: so you need to use a database
Leon Fayer
 

Viewers also liked (13)

PPTX
QCon - 一次 Clojure Web 编程实战
dennis zhuang
 
PDF
Java 与 CPU 高速缓存
dennis zhuang
 
PDF
Phoenix demysitify, with fun
Tai An Su
 
PDF
Elixir
Mohammed Cherif
 
PDF
Elixir introd
dennis zhuang
 
PDF
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Greg Vaughn
 
PDF
Introducing Elixir the easy way
Tobias Pfeiffer
 
PDF
Erlang scheduler
dennis zhuang
 
PDF
Bottleneck in Elixir Application - Alexey Osipenko
Elixir Club
 
ODP
Elixir basics
Ruben Amortegui
 
PDF
Learn Elixir at Manchester Lambda Lounge
Chi-chi Ekweozor
 
PPTX
Nintendo presentation 3.0
Ignacio Continente
 
QCon - 一次 Clojure Web 编程实战
dennis zhuang
 
Java 与 CPU 高速缓存
dennis zhuang
 
Phoenix demysitify, with fun
Tai An Su
 
Elixir introd
dennis zhuang
 
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Greg Vaughn
 
Introducing Elixir the easy way
Tobias Pfeiffer
 
Erlang scheduler
dennis zhuang
 
Bottleneck in Elixir Application - Alexey Osipenko
Elixir Club
 
Elixir basics
Ruben Amortegui
 
Learn Elixir at Manchester Lambda Lounge
Chi-chi Ekweozor
 
Nintendo presentation 3.0
Ignacio Continente
 
Ad

Similar to PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool" (20)

PDF
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
 
KEY
Refactor like a boss
gsterndale
 
PDF
Ruby Intro {spection}
Christian KAKESA
 
PDF
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
PDF
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
GeeksLab Odessa
 
PDF
Designing Ruby APIs
Wen-Tien Chang
 
KEY
Ruby
Kerry Buckley
 
PDF
API first with Swagger and Scala by Slava Schmidt
JavaDayUA
 
KEY
An introduction to Ruby
Wes Oldenbeuving
 
PDF
Ruby 101
Harisankar P S
 
PDF
Ruby 程式語言入門導覽
Wen-Tien Chang
 
PDF
Introduction to Elixir
brien_wankel
 
PDF
CS169 UC Berkeley Armando Fox Ruby basics
AnshGanatra
 
PDF
Ruby 入門 第一次就上手
Wen-Tien Chang
 
PDF
Ruby and Rails by Example (GeekCamp edition)
bryanbibat
 
PDF
Elixir for rubysts
Danni Friedland
 
PDF
7li7w devcon5
Kerry Buckley
 
ODP
Very basic functional design patterns
Tomasz Kowal
 
KEY
Redis, Resque & Friends
Christopher Spring
 
PPTX
Day 1 - Intro to Ruby
Barry Jones
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
 
Refactor like a boss
gsterndale
 
Ruby Intro {spection}
Christian KAKESA
 
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
QA Lab: тестирование ПО. Станислав Шмидт: "Self-testing REST APIs with API Fi...
GeeksLab Odessa
 
Designing Ruby APIs
Wen-Tien Chang
 
API first with Swagger and Scala by Slava Schmidt
JavaDayUA
 
An introduction to Ruby
Wes Oldenbeuving
 
Ruby 101
Harisankar P S
 
Ruby 程式語言入門導覽
Wen-Tien Chang
 
Introduction to Elixir
brien_wankel
 
CS169 UC Berkeley Armando Fox Ruby basics
AnshGanatra
 
Ruby 入門 第一次就上手
Wen-Tien Chang
 
Ruby and Rails by Example (GeekCamp edition)
bryanbibat
 
Elixir for rubysts
Danni Friedland
 
7li7w devcon5
Kerry Buckley
 
Very basic functional design patterns
Tomasz Kowal
 
Redis, Resque & Friends
Christopher Spring
 
Day 1 - Intro to Ruby
Barry Jones
 
Ad

Recently uploaded (20)

PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
PDF
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Presentation about variables and constant.pptx
kr2589474
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
How to Download and Install ADT (ABAP Development Tools) for Eclipse IDE | SA...
SAP Vista, an A L T Z E N Company
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 

PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"