SlideShare a Scribd company logo
Functional Programming With Elixir
Nguyen Anh Tien
Table of Contents
● What is Elixir ?
● Functional Programming
● Why Elixir ?
● Syntax of Elixir
● Elixir’s Ecosystem
● Q & A
2
What is Elixir ?
● Functional, Concurrent, General Purpose
● Created by José Valim @ Plataformatec
○ Former Rails Core Team member
○ Author of Crafting Rails 4 Application
● Run on Erlang VM
● Stable release: 1.3.1
● Used by: Pinterest, Dockyard, Bleacher Report, ...
3
What is Elixir ? - Erlang
● Developed by Ericsson, ~1986
● Same characteristic as Elixir
● Used in Telephone Applications
● BEAM VM
○ A virtual machine to run Erlang
○ Interfaces to the “outside” world
● Backed of WhatApp, Amazon’s SimpleDB, ...
○ http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19
-billion.html
○ https://blog.whatsapp.com/196/1-million-is-so-2011
● Battle-tested !
4
Functional vs Imperative Programming
● Modules
● Immutable
● Pure functions
○ No side-effect
● Stateless ?
● Declarative
○ Expressions
● Erlang, Haskell, Clojure, ...
● Objects
● Mutable
● Methods
○ Can have side-effect
● Stateful
● Imperative
○ Statements
● Python, Ruby, Java
5
Elixir’s Syntax - Types
Integer 1234 0xcafe 0177 0b100 10_000
Float 1.0 3.1415 6.02e23
Atom :foo :me@home :"with spaces"
Tuple { 1, 2, :ok, "xy" }
List [ 1, 2, 3 ] or [head | tail]
Keyword List [ a: "Foo", b: 123 ]
Map %{ key => value, key => value }
Truth true, false, nil
Range a..b
6
Elixir’s Syntax - Ruby like
7
Elixir’s Syntax
● First class functions - High order functions
○ Functions that can either take other functions as arguments or return them as results
○ Macro 
○ Homoiconicity
● Anonymous functions
Data Function Function Data
transformation
transformation
8
Elixir’s Syntax - Pipe operator (1)
● |>
○ passes the result of an expression as the first parameter of another expression.
● First argument: Data to transform
● Function composing
● Normal (bad) code
9
Elixir’s Syntax - Pipe operator (2)
● Nested code
● Pipe code
10
Elixir’s Syntax - Pattern Matching (1)
● the = operator is actually a match operator -> binding + rebinding
11
Elixir’s Syntax - Pattern Matching (2)
● Function signature matching
12
Elixir’s Syntax - Looping
● Looping through recursion, tail-call
● Iteration
○ Enum.reduce
○ Enum.map
○ Enum.filter
○ ...
13
Why Elixir ? Processes
● Processes
○ Lightweight, low cost (~1KB)
○ Isolated, concurrent
○ Thousand of processes
● Communication by message-passing
○ Inbox
● Connect to other node in another computer
● -> Distributed
14
Why Elixir ? Fast (1)
● Data copying
○ -> inefficient ?
● Garbage Collector
○ Processes have separated
heap
○ No synchronisation
● Robert Virding - Hitchhiker's
Tour of the BEAM
○ https://www.youtube.com
/watch?v=_Pwlvy3zz9M
15
Why Elixir ? Fast (2)
● Let’s see some
benchmark
○ https://github.com/mroth/
phoenix-showdown
16
Why Elixir ? Fault-tolerant (1)
● Todo Server Example
○ Everyone have a Todo
○ Todo: List of todo items
● Use cache when DB
isn’t reachable
● One user’s todo list do
not affect other’s todo
list
17
Why Elixir ? Fault-tolerant (2)
● “Let it crash”
● Link and Monitor
● OTP
● Supervisor Trees -
GenServer
● Restart Strategy
○ one_for_one
○ simple_one_for_one
○ rest_for_one
18
Elixir’s Ecosystem
● Hex - The package manager for the Erlang ecosystem
● Mix - Elixir’s build tool
○ = Rake + Bundler + RubyGems
● Call outside program via Ports or NIF
19
Elixir’s Ecosystem
● Productive - Reliable - Fast
● MVC model, Plug based
● Live reload coding
● Websocket integrated
○ http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-c
onnections
○ https://dockyard.com/blog/2016/08/09/phoenix-channels-vs-rails-action-
cable
● More and more app migration from
Rails to Phoenix
○ https://speakerdeck.com/bcardarella/fro
m-rails-to-phoenix
20
Learning Resources
● Elixir Getting Started
● Elixir Schools
● ElixirConf @ youtube
● #elixir @ confreaks.tv
● exercism.io
● vietnamrb.slack.com
● Elixir-lang.slack.com
● Erlang stuffs !
● ...
21
Q & A
22
23
Thank you !

More Related Content

What's hot

Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
davanum
 
History of programming languages
History of programming languagesHistory of programming languages
History of programming languages
twuniversity
 
Dynamic in C# 4.0
Dynamic in C# 4.0Dynamic in C# 4.0
Dynamic in C# 4.0
morrisBahrami
 
Elixir otp-basics
Elixir otp-basicsElixir otp-basics
Elixir otp-basics
Ruben Amortegui
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
Matthew Campbell
 
A bit more of PE
A bit more of PEA bit more of PE
A bit more of PE
Ange Albertini
 
Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdfSprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
Christian Zellot
 
Tofu and its environment
Tofu and its environmentTofu and its environment
Tofu and its environment
Kirill Shelopugin
 
Introduction to Go for Java Developers
Introduction to Go for Java DevelopersIntroduction to Go for Java Developers
Introduction to Go for Java Developers
Laszlo Csontos
 
NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?Eric Evans
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
Introduction to f#
Introduction to f#Introduction to f#
Introduction to f#
mjyeaney
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
GraphQL is actually rest
GraphQL is actually restGraphQL is actually rest
GraphQL is actually rest
Jakub Riedl
 
IDLs
IDLsIDLs
Children of Ruby
Children of RubyChildren of Ruby
Children of Ruby
Simon St.Laurent
 
Functional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in ScalaFunctional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in Scala
kellogh
 

What's hot (20)

Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
 
History of programming languages
History of programming languagesHistory of programming languages
History of programming languages
 
Dynamic in C# 4.0
Dynamic in C# 4.0Dynamic in C# 4.0
Dynamic in C# 4.0
 
Elixir otp-basics
Elixir otp-basicsElixir otp-basics
Elixir otp-basics
 
Ruxmon.2015-08.-.proxenet
Ruxmon.2015-08.-.proxenetRuxmon.2015-08.-.proxenet
Ruxmon.2015-08.-.proxenet
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
 
A bit more of PE
A bit more of PEA bit more of PE
A bit more of PE
 
Sprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdfSprint Boot & Kotlin - Meetup.pdf
Sprint Boot & Kotlin - Meetup.pdf
 
Tofu and its environment
Tofu and its environmentTofu and its environment
Tofu and its environment
 
Introduction to Go for Java Developers
Introduction to Go for Java DevelopersIntroduction to Go for Java Developers
Introduction to Go for Java Developers
 
NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
 
Introduction to f#
Introduction to f#Introduction to f#
Introduction to f#
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
GraphQL is actually rest
GraphQL is actually restGraphQL is actually rest
GraphQL is actually rest
 
IDLs
IDLsIDLs
IDLs
 
Children of Ruby
Children of RubyChildren of Ruby
Children of Ruby
 
Functional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in ScalaFunctional Programming and Concurrency Patterns in Scala
Functional Programming and Concurrency Patterns in Scala
 

Viewers also liked

The legendary-book
The legendary-bookThe legendary-book
The legendary-book
Huy Hoàng Phạm
 
Growing ELIXIR-UK
Growing ELIXIR-UKGrowing ELIXIR-UK
Growing ELIXIR-UK
jmhancock
 
Enfermedades raras
Enfermedades rarasEnfermedades raras
Enfermedades raras
Franco Vecchio
 
Enfermedades RARAS
Enfermedades RARASEnfermedades RARAS
Enfermedades RARAS
adrimar2450
 
Elixir
ElixirElixir
Elixir
Robert Brown
 
Las Enfermedades Raras
Las Enfermedades Raras Las Enfermedades Raras
Las Enfermedades Raras
Gustavo A. Grima
 
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita HendricusdottirCoordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
ELIXIR UK
 
Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015
ilsintelligence
 
The ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole GobleThe ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole Goble
ELIXIR UK
 
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
Niall Beard
 
An introduction to Erlang and Elixir
An introduction to Erlang and ElixirAn introduction to Erlang and Elixir
An introduction to Erlang and Elixirericbmerritt
 
Elixir
ElixirElixir
La Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNSLa Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNS
Plan de Calidad para el SNS
 
¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?
Ruben Lijo
 
Enfermedades Raras y Crónicas
Enfermedades Raras y CrónicasEnfermedades Raras y Crónicas
Enfermedades Raras y Crónicas
Pedro Roberto Casanova
 
Medicamentos huérfanos
Medicamentos huérfanosMedicamentos huérfanos
Medicamentos huérfanos
Mar Sánchez
 

Viewers also liked (20)

The legendary-book
The legendary-bookThe legendary-book
The legendary-book
 
Growing ELIXIR-UK
Growing ELIXIR-UKGrowing ELIXIR-UK
Growing ELIXIR-UK
 
Enfermedades raras
Enfermedades rarasEnfermedades raras
Enfermedades raras
 
Enfermedades RARAS
Enfermedades RARASEnfermedades RARAS
Enfermedades RARAS
 
Elixir
ElixirElixir
Elixir
 
Las Enfermedades Raras
Las Enfermedades Raras Las Enfermedades Raras
Las Enfermedades Raras
 
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita HendricusdottirCoordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
 
Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015
 
The ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole GobleThe ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole Goble
 
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
 
An introduction to Erlang and Elixir
An introduction to Erlang and ElixirAn introduction to Erlang and Elixir
An introduction to Erlang and Elixir
 
Enfermedades raras II
Enfermedades raras IIEnfermedades raras II
Enfermedades raras II
 
Elixir
ElixirElixir
Elixir
 
La Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNSLa Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNS
 
¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?
 
Enfermedades Raras y Crónicas
Enfermedades Raras y CrónicasEnfermedades Raras y Crónicas
Enfermedades Raras y Crónicas
 
Medición en salud
Medición en saludMedición en salud
Medición en salud
 
Validacion de escalas de medicion en salud
Validacion de escalas de medicion en saludValidacion de escalas de medicion en salud
Validacion de escalas de medicion en salud
 
Enfermedades raras i
Enfermedades raras iEnfermedades raras i
Enfermedades raras i
 
Medicamentos huérfanos
Medicamentos huérfanosMedicamentos huérfanos
Medicamentos huérfanos
 

Similar to Functional Programming With Elixir

Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
Publitory
 
Elixir intro
Elixir introElixir intro
Elixir intro
Anton Mishchuk
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
Jorg Janke
 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang dance
Arjan
 
Onyx
OnyxOnyx
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
Ruben Amortegui
 
Reverse Engineering 101
Reverse Engineering 101Reverse Engineering 101
Reverse Engineering 101
GDSC UofT Mississauga
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
bennuttall
 
Helidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptxHelidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptx
Dmitry Kornilov
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologiesElectron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherCharles Nutter
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
Eytan Daniyalzade
 
MacGyver Learns Spark
MacGyver Learns SparkMacGyver Learns Spark
MacGyver Learns Spark
Jared Holmberg
 
Assignment 1-mtat
Assignment 1-mtatAssignment 1-mtat
Assignment 1-mtatzafargilani
 
Phoenix Framework for the realtime web
Phoenix Framework for the realtime webPhoenix Framework for the realtime web
Phoenix Framework for the realtime web
Pedro Medeiros
 
Python Generators
Python GeneratorsPython Generators
Python Generators
Akshar Raaj
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
brien_wankel
 
Facebook chat architecture
Facebook chat architectureFacebook chat architecture
Facebook chat architecture
Udaya Kiran
 
Eugene letuchy erlangatfacebook
Eugene letuchy erlangatfacebookEugene letuchy erlangatfacebook
Eugene letuchy erlangatfacebookbillowqiu
 

Similar to Functional Programming With Elixir (20)

Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
Elixir intro
Elixir introElixir intro
Elixir intro
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Duo Disco - doing the Erlang dance
Duo Disco - doing the Erlang danceDuo Disco - doing the Erlang dance
Duo Disco - doing the Erlang dance
 
Onyx
OnyxOnyx
Onyx
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
 
Reverse Engineering 101
Reverse Engineering 101Reverse Engineering 101
Reverse Engineering 101
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
Helidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptxHelidon Nima - Loom based microserfice framework.pptx
Helidon Nima - Loom based microserfice framework.pptx
 
Electron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologiesElectron JS | Build cross-platform desktop applications with web technologies
Electron JS | Build cross-platform desktop applications with web technologies
 
JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform Further
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
 
MacGyver Learns Spark
MacGyver Learns SparkMacGyver Learns Spark
MacGyver Learns Spark
 
Assignment 1-mtat
Assignment 1-mtatAssignment 1-mtat
Assignment 1-mtat
 
Phoenix Framework for the realtime web
Phoenix Framework for the realtime webPhoenix Framework for the realtime web
Phoenix Framework for the realtime web
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Facebook chat architecture
Facebook chat architectureFacebook chat architecture
Facebook chat architecture
 
Eugene letuchy erlangatfacebook
Eugene letuchy erlangatfacebookEugene letuchy erlangatfacebook
Eugene letuchy erlangatfacebook
 

More from Framgia Vietnam

Timeless - Websocket on Rails
Timeless - Websocket on RailsTimeless - Websocket on Rails
Timeless - Websocket on RailsFramgia Vietnam
 
Game Development with Pygame
Game Development with PygameGame Development with Pygame
Game Development with Pygame
Framgia Vietnam
 
CSS3 Lovers, Gather Together
CSS3 Lovers, Gather TogetherCSS3 Lovers, Gather Together
CSS3 Lovers, Gather TogetherFramgia Vietnam
 
Build public private cloud using openstack
Build public private cloud using openstackBuild public private cloud using openstack
Build public private cloud using openstackFramgia Vietnam
 
Introduction to JRuby And JRuby on Rails
Introduction to JRuby And JRuby on RailsIntroduction to JRuby And JRuby on Rails
Introduction to JRuby And JRuby on RailsFramgia Vietnam
 
Some ways to DRY in Rails
Some ways to DRY in Rails Some ways to DRY in Rails
Some ways to DRY in Rails
Framgia Vietnam
 
Create 3D objects insite Cocos2d-x
Create 3D objects insite Cocos2d-xCreate 3D objects insite Cocos2d-x
Create 3D objects insite Cocos2d-xFramgia Vietnam
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptFramgia Vietnam
 
Organize directories for applications with front-end and back-end with yii - ...
Organize directories for applications with front-end and back-end with yii - ...Organize directories for applications with front-end and back-end with yii - ...
Organize directories for applications with front-end and back-end with yii - ...
Framgia Vietnam
 
What is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNTWhat is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNTFramgia Vietnam
 
Audited activerecord - QuanHV
Audited activerecord - QuanHVAudited activerecord - QuanHV
Audited activerecord - QuanHVFramgia Vietnam
 
Client side validations gem - KhanhHD
Client side validations gem - KhanhHDClient side validations gem - KhanhHD
Client side validations gem - KhanhHDFramgia Vietnam
 
Backbone.js and rails - BanLV
Backbone.js and rails - BanLVBackbone.js and rails - BanLV
Backbone.js and rails - BanLVFramgia Vietnam
 
Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuFramgia Vietnam
 

More from Framgia Vietnam (20)

Dreamers defense
Dreamers defenseDreamers defense
Dreamers defense
 
Timeless - Websocket on Rails
Timeless - Websocket on RailsTimeless - Websocket on Rails
Timeless - Websocket on Rails
 
Game Development with Pygame
Game Development with PygameGame Development with Pygame
Game Development with Pygame
 
Racer Mice - Game Team
Racer Mice - Game TeamRacer Mice - Game Team
Racer Mice - Game Team
 
CSS3 Lovers, Gather Together
CSS3 Lovers, Gather TogetherCSS3 Lovers, Gather Together
CSS3 Lovers, Gather Together
 
Java 8 new features
Java 8 new features Java 8 new features
Java 8 new features
 
Build public private cloud using openstack
Build public private cloud using openstackBuild public private cloud using openstack
Build public private cloud using openstack
 
Introduction to JRuby And JRuby on Rails
Introduction to JRuby And JRuby on RailsIntroduction to JRuby And JRuby on Rails
Introduction to JRuby And JRuby on Rails
 
Some ways to DRY in Rails
Some ways to DRY in Rails Some ways to DRY in Rails
Some ways to DRY in Rails
 
HTML5 DRAG AND DROP
HTML5 DRAG AND DROPHTML5 DRAG AND DROP
HTML5 DRAG AND DROP
 
Create 3D objects insite Cocos2d-x
Create 3D objects insite Cocos2d-xCreate 3D objects insite Cocos2d-x
Create 3D objects insite Cocos2d-x
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
Organize directories for applications with front-end and back-end with yii - ...
Organize directories for applications with front-end and back-end with yii - ...Organize directories for applications with front-end and back-end with yii - ...
Organize directories for applications with front-end and back-end with yii - ...
 
What is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNTWhat is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNT
 
An idea - NghiaLV
An idea - NghiaLVAn idea - NghiaLV
An idea - NghiaLV
 
Audited activerecord - QuanHV
Audited activerecord - QuanHVAudited activerecord - QuanHV
Audited activerecord - QuanHV
 
Delegate - KhanhLD
Delegate - KhanhLDDelegate - KhanhLD
Delegate - KhanhLD
 
Client side validations gem - KhanhHD
Client side validations gem - KhanhHDClient side validations gem - KhanhHD
Client side validations gem - KhanhHD
 
Backbone.js and rails - BanLV
Backbone.js and rails - BanLVBackbone.js and rails - BanLV
Backbone.js and rails - BanLV
 
Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh Vu
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

Functional Programming With Elixir

  • 1. Functional Programming With Elixir Nguyen Anh Tien
  • 2. Table of Contents ● What is Elixir ? ● Functional Programming ● Why Elixir ? ● Syntax of Elixir ● Elixir’s Ecosystem ● Q & A 2
  • 3. What is Elixir ? ● Functional, Concurrent, General Purpose ● Created by José Valim @ Plataformatec ○ Former Rails Core Team member ○ Author of Crafting Rails 4 Application ● Run on Erlang VM ● Stable release: 1.3.1 ● Used by: Pinterest, Dockyard, Bleacher Report, ... 3
  • 4. What is Elixir ? - Erlang ● Developed by Ericsson, ~1986 ● Same characteristic as Elixir ● Used in Telephone Applications ● BEAM VM ○ A virtual machine to run Erlang ○ Interfaces to the “outside” world ● Backed of WhatApp, Amazon’s SimpleDB, ... ○ http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19 -billion.html ○ https://blog.whatsapp.com/196/1-million-is-so-2011 ● Battle-tested ! 4
  • 5. Functional vs Imperative Programming ● Modules ● Immutable ● Pure functions ○ No side-effect ● Stateless ? ● Declarative ○ Expressions ● Erlang, Haskell, Clojure, ... ● Objects ● Mutable ● Methods ○ Can have side-effect ● Stateful ● Imperative ○ Statements ● Python, Ruby, Java 5
  • 6. Elixir’s Syntax - Types Integer 1234 0xcafe 0177 0b100 10_000 Float 1.0 3.1415 6.02e23 Atom :foo :me@home :"with spaces" Tuple { 1, 2, :ok, "xy" } List [ 1, 2, 3 ] or [head | tail] Keyword List [ a: "Foo", b: 123 ] Map %{ key => value, key => value } Truth true, false, nil Range a..b 6
  • 7. Elixir’s Syntax - Ruby like 7
  • 8. Elixir’s Syntax ● First class functions - High order functions ○ Functions that can either take other functions as arguments or return them as results ○ Macro  ○ Homoiconicity ● Anonymous functions Data Function Function Data transformation transformation 8
  • 9. Elixir’s Syntax - Pipe operator (1) ● |> ○ passes the result of an expression as the first parameter of another expression. ● First argument: Data to transform ● Function composing ● Normal (bad) code 9
  • 10. Elixir’s Syntax - Pipe operator (2) ● Nested code ● Pipe code 10
  • 11. Elixir’s Syntax - Pattern Matching (1) ● the = operator is actually a match operator -> binding + rebinding 11
  • 12. Elixir’s Syntax - Pattern Matching (2) ● Function signature matching 12
  • 13. Elixir’s Syntax - Looping ● Looping through recursion, tail-call ● Iteration ○ Enum.reduce ○ Enum.map ○ Enum.filter ○ ... 13
  • 14. Why Elixir ? Processes ● Processes ○ Lightweight, low cost (~1KB) ○ Isolated, concurrent ○ Thousand of processes ● Communication by message-passing ○ Inbox ● Connect to other node in another computer ● -> Distributed 14
  • 15. Why Elixir ? Fast (1) ● Data copying ○ -> inefficient ? ● Garbage Collector ○ Processes have separated heap ○ No synchronisation ● Robert Virding - Hitchhiker's Tour of the BEAM ○ https://www.youtube.com /watch?v=_Pwlvy3zz9M 15
  • 16. Why Elixir ? Fast (2) ● Let’s see some benchmark ○ https://github.com/mroth/ phoenix-showdown 16
  • 17. Why Elixir ? Fault-tolerant (1) ● Todo Server Example ○ Everyone have a Todo ○ Todo: List of todo items ● Use cache when DB isn’t reachable ● One user’s todo list do not affect other’s todo list 17
  • 18. Why Elixir ? Fault-tolerant (2) ● “Let it crash” ● Link and Monitor ● OTP ● Supervisor Trees - GenServer ● Restart Strategy ○ one_for_one ○ simple_one_for_one ○ rest_for_one 18
  • 19. Elixir’s Ecosystem ● Hex - The package manager for the Erlang ecosystem ● Mix - Elixir’s build tool ○ = Rake + Bundler + RubyGems ● Call outside program via Ports or NIF 19
  • 20. Elixir’s Ecosystem ● Productive - Reliable - Fast ● MVC model, Plug based ● Live reload coding ● Websocket integrated ○ http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-c onnections ○ https://dockyard.com/blog/2016/08/09/phoenix-channels-vs-rails-action- cable ● More and more app migration from Rails to Phoenix ○ https://speakerdeck.com/bcardarella/fro m-rails-to-phoenix 20
  • 21. Learning Resources ● Elixir Getting Started ● Elixir Schools ● ElixirConf @ youtube ● #elixir @ confreaks.tv ● exercism.io ● vietnamrb.slack.com ● Elixir-lang.slack.com ● Erlang stuffs ! ● ... 21