Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elixir – Belarus Ruby User Group 25 Jan 2014
Search
Sergey Nartimov
January 25, 2014
Programming
3
650
Elixir – Belarus Ruby User Group 25 Jan 2014
Sergey Nartimov
January 25, 2014
Tweet
Share
More Decks by Sergey Nartimov
See All by Sergey Nartimov
PubSub at Rails
lest
0
120
Rails in production - RubyConfBY 22 Mar 2015
lest
1
140
Sequel - BRUG 21 Feb 2015
lest
0
77
Authentication Security – RUBYSPB
lest
2
150
Geospatial applications on Rails
lest
8
390
Design patterns – Belarus Ruby on Rails User Group 23 Feb 2013
lest
8
640
Ruby Stdlib – Minsk.rb October 2012
lest
10
340
Background jobs with realtime results – RailsClub'Moscow 2012
lest
5
210
Other Decks in Programming
See All in Programming
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
情報漏洩させないための設計
kubotak
3
310
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
テストコード書いてみませんか?
onopon
2
130
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
130
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
480
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
830
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
CSC305 Lecture 26
javiergs
PRO
0
140
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Producing Creativity
orderedlist
PRO
341
39k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
How to Ace a Technical Interview
jacobian
276
23k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Bash Introduction
62gerente
608
210k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Transcript
Elixir Сергей Нартымов Brainspec https://github.com/lest twitter: @just_lest
Elixir is a metaprogrammable, functional language built atop the Erlang
VM.
Elixir
Metaprogramming
Metaprogramming iex> nil?(1) false iex> nil?(nil) true defmacro nil?(x) do
quote do: unquote(x) == nil end
Metaprogramming iex> nil?(1) false iex> nil?(nil) true defmacro nil?(x) do
quote do: unquote(x) == nil end
Metaprogramming if(foo, do: bar, else: baz) if foo do bar
else baz end
Metaprogramming defmacro unless(clause, options) do do_clause = Keyword.get(options, :do, nil)
else_clause = Keyword.get(options, :else, nil) quote do if(unquote(clause), do: unquote(else_clause), else: unquote(do_clause)) end end
Metaprogramming Lisps traditionally empowered developers because you can eliminate anything
that’s tedious through macros, and that power is really what people keep going back for. — Rich Hickey
Functions
Function capture iex> list = ["foo", "bar", "baz"] ["foo","bar","baz"] iex>
Enum.map list, fn(x) -> size(x) end [3,3,3] iex> Enum.map list, &size/1 [3,3,3] iex> fun = &rem(&1, 2) #Function<6.80484245 in :erl_eval.expr/5> iex> fun.(4) 0
Function capture iex> list = ["foo", "bar", "baz"] ["foo","bar","baz"] iex>
Enum.map list, fn(x) -> size(x) end [3,3,3] iex> Enum.map list, &size/1 [3,3,3] iex> fun = &rem(&1, 2) #Function<6.80484245 in :erl_eval.expr/5> iex> fun.(4) 0
Partial application iex> list = ["foo", "bar", "baz"] ["foo","bar","baz"] iex>
Enum.map list, fn(x) -> size(x) end [3,3,3] iex> Enum.map list, &size/1 [3,3,3] iex> fun = &rem(&1, 2) #Function<6.80484245 in :erl_eval.expr/5> iex> fun.(4) 0
Pipeline operator
f3(f2(f1(state))) state |> f1 |> f2 |> f3
f3(f2(f1(state))) state |> f1 |> f2 |> f3
list |> Enum.filter(&(&1 > 0)) # take positive numbers |>
Enum.map(&(&1 * &1)) # square each one |> Enum.reduce(0, &(&1 + &2)) # calculate sum
Polymorphism
Protocols
Protocols defprotocol Inspect do def inspect(thing, opts) end defimpl Inspect,
for: Atom do def inspect(false), do: "false" def inspect(true), do: "true" def inspect(nil), do: "nil" def inspect(atom) do # ... end end
Protocols defimpl Inspect, for: List do # ... end defimpl
Inspect, for: Integer do # ... end
ExUnit A unit test framework
ExUnit ExUnit.start defmodule MyTest do use ExUnit.Case test "the truth"
do assert true end end $ elixir assertion_test.exs
ExUnit ExUnit.start defmodule MyTest do use ExUnit.Case test "the truth"
do assert true end end $ elixir assertion_test.exs
ExUnit assert 1 + 1 == 2 refute 1 +
3 == 3 assert 1 + 1 == 3 # Expected 2 to be equal to (==) 3
Mix A build tool
Mix defmodule MyProject.Mixfile do use Mix.Project def project do [
app: :my_project, version: "0.0.1", deps: deps ] end # Configuration for the OTP application def application do [] end defp deps do [] end end
Mix defp deps do [ { :some_project, github: "some_project/other", tag:
"0.3.0" }, { :another_project, ">= 1.0.2", git: "https://example.com/another/repo.git" } ] end
Other
Other • Unicode strings
Other • Unicode strings • String sigils, heredocs
Other • Unicode strings • String sigils, heredocs • Documentation
Other • Unicode strings • String sigils, heredocs • Documentation
• List comprehentions
Resources • http://elixir-lang.org/ • http://joearms.github.io/2013/05/31/a-week- with-elixir.html • http://www.theerlangelist.com/2014/01/ why-elixir.html •
http://devintorr.es/blog/2013/06/11/elixir- its-not-about-syntax/
Спасибо https://github.com/lest twitter: @just_lest Сергей Нартымов Brainspec