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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Sergey Nartimov
January 25, 2014
Programming
670
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Elixir – Belarus Ruby User Group 25 Jan 2014
Sergey Nartimov
January 25, 2014
More Decks by Sergey Nartimov
See All by Sergey Nartimov
PubSub at Rails
lest
0
140
Rails in production - RubyConfBY 22 Mar 2015
lest
1
160
Sequel - BRUG 21 Feb 2015
lest
0
97
Authentication Security – RUBYSPB
lest
2
200
Geospatial applications on Rails
lest
8
440
Design patterns – Belarus Ruby on Rails User Group 23 Feb 2013
lest
8
660
Ruby Stdlib – Minsk.rb October 2012
lest
10
420
Background jobs with realtime results – RailsClub'Moscow 2012
lest
5
230
Other Decks in Programming
See All in Programming
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.2k
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
400
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
1.1k
Modding RubyKaigi for Myself
yui_knk
0
890
AI時代のUIはどこへ行く?その2!
yusukebe
19
6.7k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
RTSPクライアントを自作してみた話
simotin13
0
490
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
170
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
4.2k
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
250
Featured
See All Featured
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
770
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
390
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Docker and Python
trallard
47
3.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
ラッコキーワード サービス紹介資料
rakko
1
3.6M
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Balancing Empowerment & Direction
lara
6
1.1k
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