As a developer, you’ve probably heard that functional programming techniques help manage the complexities of today’s real-world, concurrent systems. You’re also investigating designs that help you maximize uptime and manage security.
This book is your guide to Elixir, a modern, functional, and concurrent programming language. Because Elixir runs on the Erlang VM, and uses the underlying Erlang/OTP architecture, it benefits from almost 20 years of research into high performance, highly parallel, and seriously robust applications. Elixir brings a lot that’s new: a modern, Ruby-like, extendable syntax, compile and runtime evaluation, a hygienic macro system, and more.
But, just as importantly, Elixir brings a sense of enjoyment to parallel, functional programming. Your applications become fun to work with, and the language encourages you to experiment.
Part 1 covers the basics of writing sequential Elixir programs. We’ll look at the language, the tools, and the conventions.
Part 2 uses these skills to start writing concurrent code—applications that use all the cores on your machine, or all the machines on your network! And we do it both with and without OTP.
And Part 3 looks at the more advanced features of the language, from DSLs and code generation to extending the syntax.
By the end of this book, you’ll understand Elixir, and know how to apply it to solve your complex, modern problems.
Contents and Extracts
This book is currently in beta, so the contents and extracts will change as the book is developed.
Preface/Introduction
Conventional Programming
Pattern Matching
Assignment: I do not think it means what you think it means
More Complex Matches
Ignoring a Value With _
Variables Bind Once (Per Match)
Another way of looking at the equals sign
Immutability
You Already Have (Some) Immutable Data
Immutable Data Is Known Data
Performance Implications of Immutability
Coding With Immutable Data
Elixir Basics excerpt
Value Types
System Types
Collection Types
Names, Source Files, Conventions, Operators, and So On
End of the Basics
Anonymous Functions
Functions and Pattern Matching
One Function, Multiple Bodies
Functions Can Return Functions
Passing Functions as Arguments
Functions Are The Core
Modules and Named Functions
The Body of the Function is a Block
Function Calls and Pattern Matching
Guard Clauses
Default Parameters
|> — The Amazing Pipe Operator
Modules
Module Attributes
Module Names: Elixir, Erlang, and Atoms
Lists and Recursion
Heads and Tails
Using Head and Tail to Process a List
Using Head and Tail to Build a List
Creation of a Map Function
Keeping Track of Values During Recursion
More Complex List Patterns
List Comprehensions
Using the Built-in Libraries
Strings and Binaries
String Literals
The Name “strings”
Single Quoted Strings—Lists of Character Codes
Binaries
Double Quoted Strings are Binaries
Binaries and Pattern Matching
Records
Defining Records: defrecord
Records and Pattern Matching
Advanced Records
Control Flow
if and unless
cond
case
Raising Exceptions
Designing With Exceptions
What we’ve seen
Organizing a Project
The Project: Fetch Issues from Github
Task: Use Mix to Create our New Project
Transformation: Parse the Command Line
Step: Write Some Basic Tests
Transformation: Fetch from Github
Task: Use External Libraries
Transformation: Convert Response
Transformation: Take First N Items
Transformation: Format the Table
Task: Make a command line executable (#sec.cmd-line}
Task: Test The Comments
Task: Create Project Documentation
What We’ve Just Seen
Concurrent Programming
Working With Multiple Processes
A Simple Process
Process Overhead
When Processes Die
Parallel Map—The Hello World of Erlang
A Fibonacci Server
What’s Next
Nodes—The Key To Distributing Services excerpt
Naming Nodes
Naming Your Processes
I/O, PIDs, and Nodes
What’s Next
OTP: Servers
Some OTP Definitions
An OTP Server
GenServer Callbacks
Naming A Process
Tidying Up The Interface
What We Learned
OTP: Supervisors
Supervisors And Workers
Supervisors Are The Heart of Reliability
OTP: Applications
Application: I do not think it means what you think it means
The Application Specification File
Turning Our Sequence Program into an OTP Application
Tell Mix About The Application
Create the application OTP entry point
Hot Code Swapping
OTP is Big. Unbelievably Big
Web Applications with Dynamo
More Advanced Elixir
Protocols
Use and Using
Macros
《茅理翔:创业式传承》内容简介:家族企业的传承已经成为民企发展过程中的一道难题,方太集团茅氏父子用自己的人生经验和智慧,给
AlongwithMySQLspopularityhascomeafloodofquestionsaboutsolvingspecificproblems,an...
《奔跑吧Linux内核(入门篇)》内容简介:本书是一本介绍Linux内核实践的入门书,基于Linux4.0内核,重点讲解Linux内核的理论和实验
本书内容十分丰富,涉及了集合论、指称语义、操作语义、公理语义、归纳原理、完备性、域论、信息系统、不确定性和并行性、不完备
《OpenStack高可用集群(下册)》内容简介:本书从OpenStack终端用户的角色出发,以面向生产系统的OpenStack高可用集群建设为主线,
EXCEL应用大全 本书特色 《Excel应用大全》一书适合各个层次的Excel用户,即可作为初学者的入门指南,又可作为中、高级用户的参考手册。书中大量的实例还...
Anyonewhoreadsisboundtowonder,atleastoccasionally,abouthowthosefunnysquigglesona...
ThiscomprehensiveguideshowsyouhowtomasterthemostimportantchangestoJavasinceitwas...
本书意在用这些最优秀的软件开发类文章来激励程序员们编写出更优秀的软件。我的目的很简单,就是好好编写软件。编程工作充满魅力
《设计师摄影指南》是一本“怎样”之书,目的是提高设计师和摄影者的创造能力和技巧与悟性,使设计作品更具独创性。无论你是业余
“本书是Summit以及CFAQ在线列表的许多参与者多年心血的结晶,是C语言界最为珍贵的财富之一。我向所有C语言程序员推荐本书。”—
信息通信网络是对包括电信网络、计算机网络和新一代网络等在内的各类网络的总称。本书对这些网络在系统层面上就它们的基本概念、
《计算机软件技术基础(第3版)》是计算机基础教材,全书较系统、通俗地介绍了计算机软件的技术基础知识和常用的系统软件。内容包
《中国风俗史》内容简介:作者夙有改良风俗之志,认为要理解并改良当时的风俗,不可不先述古俗。书中将黄帝以前至明朝的历史,分为
中文版AutoCAD机械设计经典技法118例-含光盘1张 本书特色 《中文版AutoCAD机械设计经典技法118例(附光盘)》编著者郭文亮、郭领艳。全书通过11...
如何判断何种灯光设计能最大限度地满足居室需要,应该使用向下的灯光?向上的灯光?地面射灯或是墙面射灯?应该选用何种类型的灯
《中共江苏地方简史》内容简介:《中共江苏地方简史》(1921—2021)是江苏省委党史工办为迎接建党100周年而编写的一本党史书籍。该
《情趣的设计世界:张剑产品设计作品选》作者张剑是位个子挺大但心很细致的人。我们从这本集子中可以看出了这一点。他非常关注生活
《超级谈话术》内容简介:有些问题,难以启齿,不好开口,但又事关你的利益,有些问题,一聊就“炸”,关系会僵,但你又不得不聊!
互联网在日常工作和生活中扮演日益重要的角色,互联网将如何重塑社会?本书通过汇集有关互联网文化、经济、政治角色等问题的研究