index

Symbols

! character 22, 25

? character 22, 25

[] operator 48

\ operator 30

& operator 104

&*/2 operator 103

&+/2 operator 103

&n placeholder 54

+ operator 103

++ operator 41

+P flag 367

+S 1 Erlang flag 171

<> operator 50

= 22, 79

> operators 49

|> (pipe operator) 114

~D sigil 58

~N sigil 59

~T sigil 59

~U sigil 59

A

abstraction

basic 114116

composing 116117

Access module 131

actor model 190

after clause 149

Agent API

agent-powered to-do server 276277

concurrency and 274276

ETS tables 280283

Agent module 190, 254, 267, 273275

basic use 273274

Agent.cast/2 function 274

Agent.get/2 function 274

Agent.update/2 function 274

agents

concurrency and 274276

limitations of 277280

alias expression 31

aliases 36

anonymous functions 5255

anonymous variable 72

Any alias 136

application callback, implementing 302303

:application module 300

Application.ensure_all_started/2 function 300

Application.fetch_env!/2 function 322

Application.get_env/3 function 322

Application.start/1 function 300

Application.stop/1 function 301

application/0 function 301302

applications

behavior 181, 299

configuring 321322

creating with mix tool 298299

environment 321

module 182, 300, 321

resource file 298

area clause 82

area(unknown) clause 82

arity 30

assert macro 199200

AST (abstract syntax tree) 14

asynchronous requests 178180

atoms 3639

awaited tasks 268270

B

:bag table type 284

BEAM (Bogdan/Björn’s Erlang Abstract Machine) 5

Bench module 286, 289

Bench.run function 282

binaries 4950, 75

bitstrings 4950, 75

boilerplate, eliminating 1215

Boolean atoms 37

branching expressions 8891

C

cache, implementing 195198

:calendar.local_time/0 function 70, 78

call requests 178

callback module 175

using with supervisors 233234

caller variable 151

calls 319

capture operator 54, 101, 117

case expression 20, 90, 148, 220

cast requests 178

casts 319

checkin operation 307

checkout operation 307

child specification 230

child_spec/1 function 271

clause definition 80

cli function 362

closure 55

clusters, building fault-tolerant

detecting partitions 348349

discovering to-do servers 338343

testing 346347

to-do cache 338343

code organization 2325

comments 3435

function visibility 3031

functions 2528

code simplification 1215

:code.get_path Erlang function 64

collectable 105

Collectable protocol 137

command variable 77

comments 3435

communication between nodes 329331

compiling, for production 360361

components

config script considerations 324

configuring applications 321322

dependencies 306307

visualizing systems 310311

dependency injection, adapting pool 307310

OTP applications

application behavior 299300

creating with mix tool 298299

folder structure 304306

implementing application callback 302303

library applications 301

web server

handling requests 314317

starting server 312314

composing abstractions 116117

comprehensions 104106

concurrency 47, 141172, 192

agents and 274276

building concurrent systems

addressing process bottleneck 209211

persistence 202

errors in concurrent systems 221223

ETS tables 280283

multiple to-do lists 195

processes 213214

creating 145147

runtime considerations

shared-nothing concurrency 170

unlimited process mailboxes 169170

schedulers, inner workings of 171172

supervision trees, supervising database workers 250253

to-do list example

analyzing process dependencies 201202

implementing cache 195198

writing tests 198201

concurrency primitives

complex states 162166

message passing 147152

registered processes 166167

stateful server processes 152156

concurrent programming

multiple to-do lists 195

persisting data

analyzing system 207209

pooling and synchronizing 212

using database 204207

writing tests, to-do list example application 198201

concurrent systems, building

persistence 202

persisting data

addressing process bottleneck 209211

pooling and synchronizing 212

reasoning with processes 213214

cond expression 8990

conditionals 8694

branching expressions 8891

Config.config_env/0 function 323

Config.config/2 function 322

conn variable 316

constants, matching 7172

control flow 69111

conditionals 8694

branching expressions 8891

iterating, with recursion 9596

loops and iterations 9499

comprehensions 104106

streams 106

tail function calls 9699

matching with functions

guards 8385

multiclause functions 8082

multiclause lambdas 8586

pattern matching

bitstrings and binaries 7577

compound matches 7778

constants 7172

general behavior 7880

matching maps 7475

variables in patterns 7273

--cookie option 351

cookies 351352

Cowboy library 312

cprof tool 371

CRUD (create, read, update, delete) operations 126128

current_sum parameter 98

D

daemon command 363

daemon_iex command 364

data abstractions 112138

composing abstractions 116117

CRUD operations 126128

hierarchical data 126134

immutable hierarchical updates 129131

importing from file 133134

iterative updates 131132

updating entries 128129

polymorphism with protocols 136

built-in protocols 137138

implementing protocols 136137

with modules

basic abstraction 114116

structs 119124

data transparency 124126

data types, first-class functions 5255

database processes 204207

database workers, supervising 250253

Date data structure 112

Date module 59, 115, 125

DateTime module 59, 125

@db_folder module attribute 204

dbg function 371

dbg macro 126, 371

:dbg module 375

debugger node 357

def expression 23, 25, 86, 88

def function 63

def macro 25, 30

default clause 82

defexception macro 221

defimpl macro 136

defmodule expression 23

defmodule function 63

defmodule macro 25

defp expression 86

defp macro 30

defrecord macro 123124

defrecordp macro 123

defstruct macro 119

delete_entry request 165

dependencies 306307

dependency injection, adapting pool 307310

deps function 299, 373

-detached erlang flag 357

detached mode 357

development platform, Erlang 910

dirty scheduler thread 171

disadvantages of Elixir, Erlang ecosystem 17

distributed systems 325354

distribution primitives

communicating between nodes 329331

links and monitors 334335

other distribution services 335337

process discovery 334

fault-tolerant clusters 337347

detecting partitions 348349

discovering to-do servers 338343

highly available systems 349350

replicated databases 343346

testing 346347

to-do cache 338343

network considerations

cookies 351352

node names 350351

primitives 327329

do block 105, 199

do/end block 104, 136

@doc attribute 33

Docker containers, packaging releases in 367369

:DOWN message 225

:duplicate_bag table type 284

DynamicSupervisor 272

DynamicSupervisor module 257

DynamicSupervisor.start_child/2 function 258

DynamicSupervisor.start_link/1 function 258

E

-e argument 281

each function 107

Elixir 3

code simplification 1215

concurrency 141172, 192

disadvantages of Erlang ecosystem 17

functions, composing 1516

script 198

elixir application 306, 365

elixir command 66, 356358

elixir my_script.exs command 358

Elixir, building blocks

code organization 2335

comments 3435

function visibility 3031

functions 2528

imports and aliases 3132

module attributes 3234

modules 2325

macros 6263

runtime 6367

starting 6567

type system 3561

atoms 3739

first-class functions 5255

immutability 4346

IO lists 6061

lists 4043

maps 4649

numbers 3536

tuples 3940

variables, overview of 2223

Enum functions 106109, 122, 134

Enum module 40, 47, 58, 100, 104105, 107, 134, 137, 289

Enum-based iterations 104

Enum.at/2 function 40, 156

Enum.each/2 function 53, 56, 100, 134, 146

Enum.filter/2 function 101102, 109

Enum.map/2 function 100, 152

Enum.reduce/3 function 102, 106

Enum.sum/1 function 103

Enum.take/2 function 107108

Enum.to_list function 107

Enum.to_list/1 function 107

Enum.with_index/1 function 106107

Enumerable protocol 137

epmd -names command 353

EPMD (Erlang Port Mapper Daemon) 353

eprof tool 371

Erlang

concurrency 47

development platform 910

ecosystem 17

high availability 47

processes 5

relationship to microservices 1011

server-side systems 79

:erlang.binary_to_term/1 function 203, 330

:erlang.memory/0 function 372

:erlang.system_info/1 function 372

:erlang.term_to_binary/1 function 203, 330

:erlang.trace/3 function 375

Erlang/OTP 9

error effects 239266

error handling

concurrent systems 221223

runtime errors 218221

supervision trees

organizing 253256

registering database workers 247249

separating loosely dependent parts 240243

error isolation approaches, dynamic supervision 257258

error kernel 263

errors 216

:ets functions 287

:ets module 288

ETS operations 289

ETS tables 267, 280283

basic operations 285

deleting rows 289291

ETS powered key-value store 285289

inserting rows 289291

key-based lookups 289291

overview of 280, 289291

process registry 292293

:ets.delete/2 function 288

:ets.insert/2 function 284, 288

:ets.lookup/2 function 284

:ets.new/2 function 284285

:ets.select/2 function 290

:ets.update_counter/4 function 288

:ets.update_element/3 function 288

EtsKeyValue module 289

ex_doc tool 33

ex_unit framework 198

ex2ms library 290

exit reason 223

exit signal 223

exits 216

:extra_applications option 372

extract_user/1 function 92

F

falsy values 38

fault tolerance 142, 215238

errors in concurrent systems, linking processes 223225

handling errors in concurrent systems 225226

runtime errors 216221

handling 218221

supervisors 226227

child specifications 230232

linking all processes 234237

preparing existing code 227228

restart frequency 237238

using callback modules 233234

wrapping 233

fetch_query_params function 316

File.mkdir_p!/1 function 204

File.read/1 function 72

File.stream!/1 function 109

files, importing from 133134

filter function 107

flush helper 330

fn expression 52

fold function 102

folder structure, OTP applications 304306

for:Type 136

fprof tool 371

fraction example 119

Fraction.new/2 function 124

Fraction.value/1 function 121

functions

anonymous 5255

arity 30

composing 1516

defined inside modules 23

first-class 5255

higher-order 99104

matching with

guards 8385

multiclause functions 8082

overview of 2528

visibility 3031

G

:"$gen_call" atom 185

:"$gen_cast" atom 185

gen_event behaviour 181

gen_server behaviour 181

:gen_server module 181

gen_statem behaviour 181

GenServer (generic server process) 153, 184, 225, 233, 245246, 270

abstraction 338

behaviours 181182

building

asynchronous requests 178180

implementing generic code 175176

refactoring to-do server using GenServer 180181

callbacks 278

features of 186189

functions 190

GenServer, plugging into 182183

handling requests 183184

loop 190

message handling, plain messages 184186

module 181183, 254255, 267

Open Telecom Platform-compliant processes 190191

OTP behaviours 181182

plugging into 182183

process life cycle 189190

refactoring to-do server using 180181

GenServer.abcast/3 function 331

GenServer.call 246

GenServer.call function 225

GenServer.call/2 function 183184

GenServer.cast 246

GenServer.cast/2 function 183184

GenServer.multi_call/4 function 331

GenServer.start invocation 206207

GenServer.start_link function 260

GenServer.start/2 function 182184, 197

GenServer.stop/3 function 189

GenStage library 190, 321

get_and_update_in/2 macro 131

get_in/2 macro 131

global module 331, 334

global.erl file 336

:global.trans/2 336

group leader 329

guards 8385

H

h command 21

handle_* callbacks 190

handle_call/2 callback function 176178

handle_call/3 callback function 183, 188189, 278

handle_call/3 clause 186

handle_cast/2 callback function 179, 183, 186, 188, 278

handle_continue/2 callback function 206207, 243

handle_info/2 callback function 185186, 188, 278

hd function 42, 74

head | tail 87

Hébert, Fred 370

Heisenbug category 221

hex package 361

Hex package manager 16, 307

--hidden argument 352

hidden nodes 352353

hidden tag 352

hierarchical data 126134

immutable hierarchical updates 129131

importing from file 133134

iterative updates 131132

updating entries 128129

high availability 47

higher-level types 5659

higher-order functions 99104

highly available systems 349350

HTTP servers, building 317

reasoning about system 317321

I

id field 127

iex -S mix command 356

iex application 365

iex command 20

iex session 28, 247

iex shell 63, 163

iex shell prompt 222

if expression 20, 63, 86, 8889

immutability 4346

@impl attribute 187

@impl GenServer function 187

@impl module attribute 187

implementation functions 153

imports and aliases 3132

in operator 41

inet_dist_listen_max environment variable 353

inet_dist_listen_min environment variable 353

__info__/1 function 182

init/0 function 175176, 178

init/1 callback 183184, 206, 228, 255, 286

inject function 102

inspect function 124, 137

Inspect protocol 137

Integer.to_string/1 function 136

intentional programming 263

interactive shell 2021

interface functions 153, 178

into option 105

IO lists 6061

IO module 23

IO.inspect 370

IO.inspect function 57, 212, 371

IO.inspect/1 function 125, 133

iterations

comprehensions 104106

iterating with recursion 9596

iterative updates 131132

K

kernel app 353

:kernel application 336

kernel application 306, 365

Kernel module 31, 61

Kernel.apply/3 function 65

Kernel.defprotocol/2 function 137

Kernel.elem/2 function 39

Kernel.inspect/1 function 124

Kernel.is_number/1 function 84

Kernel.length/1 function 40

Kernel.node/0 function 327

Kernel.put_elem/3 function 39

Kernel.put_in/2 macro 130

Kernel.send/2 function 148

Kernel.to_string/1 function 135

key-based lookups 289291

key-value stores 287

ETS powered 285289

example, handling requests 183184

keys 284

:keys option 244

keyword lists 56

Keyword module 57

Keyword.get/2 function 57

L

lambda functions 53

lambdas, multiclause 8586

let-it-crash approach

handling expected errors 264265

preserving state 265266

library applications 301

linking processes 223225

links and monitors 334335

List module 4041, 113

List.Chars protocol 137

List.first/1 function 113

List.insert_at/3 function 41, 113

List.replace_at/3 function 41

lists 4043

matching 7374

literals 170

local name 166

location transparency 329

logger application 370371

logging 371373

long names 327, 350

loops and iterations, tail function calls 9699

M

m:n threading 171

macros 6263

Map functions 123

Map module 49

Map.delete/2 function 47

Map.fetch!/2 function 47

Map.fetch/2 function 49, 129, 196

Map.get/3 function 47, 116

Map.has_key?/2 function 101

Map.new/1 function 46

Map.put/3 function 47, 49

Map.update function 129

Map.update/4 function 47, 115116

maps 4649

matching 7475

MapSet module 58, 114

MapSet.new(...) output 124

match operator 7071

match patterns 289

match specification 290

match-all anonymous variable 290

max function 89

maximum restart frequency 237

message passing 147152

messages, handling plain 184186

MFA (module, function, arguments) list 330

microservices, relationship to Erlang 1011

mix archive.install task 360

mix command 67, 356358

mix compile command 193, 307

mix deps.get command 307

mix environment 304, 323

compiling for production 360361

mix escript.build documentation 360

mix project 163

mix release command 362

mix run command 281

mix tasks 371

mix test command 67, 303, 360

mix tool 16, 67, 193, 302, 312, 321, 355356, 372

creating applications with 298299

MIX_ENV environment variable 361

MIX_ENV OS environment variable 304

Mix.install function 359

modifier functions 113

module attributes 3234

__MODULE__ form 188

@moduledoc attribute 33

modules 23

abstractions with 114

composing abstractions 116117

data transparency 124126

monitor_nodes function 349

monitors 225226, 334335

multicall function 345

multiclause functions 69, 8082

multiclause lambdas 8586

N

:name option 187, 244, 246, 308

:named_table option 285

:net_adm module 335

:net_adm.names/0 353

:net_kernel module 335

:net_kernel.monitor_nodes function 329

netsplit situations 348

--no-halt option 67, 356

--no-halt parameter 66

Node module 335

Node.connect/1 function 328

Node.get_cookie/0 function 351

Node.list([:this,:visible]) function 357

Node.list/0 function 328

Node.monitor/1 function 329

Node.monitor/2 function 349

Node.set_cookie/1 function 351

Node.set_cookie/2 function 352

Node.spawn 335

Node.spawn/2 function 329

Node.spawn/4 function 330

nodes

communicating between 329331

hidden nodes 352353

names 350351

non-awaited tasks 270272

numbers 3536

O

observer application 372373

observer tool 310

observer_cli 373

:one_for_all restart strategy 256

:one_for_one restart strategy 256

one_for_one strategy 229

Open Telecom Platform (OTP). See OTP

operators 48, 6162

:ordered_set table type 284

organizing code

function arity 30

imports and aliases 3132

module attributes 3234

OTP (Open Telecom Platform) 9, 173

applications

behavior 299300

folder structure 304306

starting 300301

behaviours 181182

compliant processes 190191

releases 361369

contents of 364367

packaging in Docker containers 367369

using 363364

P

parse transform construct 12

partition situation 338

partitions, detecting 348349

pattern 70

pattern matching

bitstrings and binaries 7577

compound matches 7778

constants 7172

general behavior 7880

match operator 7071

matching maps 7475

variables in patterns 7273

person variable 40, 70

pg (process groups) module 333

pg.erl file 336

Phoenix Framework 190, 312

Phoenix.Channel module 190

phx.new task 360

@pi constant 32

PIDs (process identifiers) 145

pin operator 73

pipe operator 28

plug

dispatch expression 315

match expression 315

Plug library 312

plug macro 315

Plug.Conn struct 316

Plug.Conn.fetch_query_params/1 function 316

Plug.Cowboy.child_spec/1 function 313

polymorphism, implementing protocols 136137

Poolboy library 306

post macro 315316

POST request 314

primitives, in distributed systems 327329

process discovery 334

process identifiers (PIDs) 145

process life cycle 189190

process mailboxes, unlimited 169170

process registry 292293

process_message/2 clause 165

process_message/2 function 161, 164

Process.exit/2 function 229

Process.info/1 function 372

Process.link/1 function 223

Process.list/0 function 198, 372

Process.sleep/1 function 169

processes 142

creating 145147

finding to-do servers 259260

linking 223225

linking all 234237

message passing 147152

starting dynamically 256257

testing system 261262

using temporary restart strategy 260261

:protected value 285

protocols 134

built-in 137138

implementing 136137

polymorphism with 136

pry feature 371

:public value 285

put operations 288

put request 179

put_elem function 39

put_in/3 macro 131

put/3 function 178

puts function 23

Q

query functions 113

query_def variable 146

R

raise/1 macro 217, 219

:rand.uniform/1 function 156

Range module 56

rebar package 361

receive clause 160

receive expression 63, 148, 220

Recon library 375

Record module 123

Record.extract/2 function 124

rectangle_area function 26

recursion 9596

reduce function 102

reductions 372

registered attributes 33

registered processes 166167

Registry implementation 248

Registry module 244245, 253, 256, 267, 292, 331

Registry.lookup/2 function 245

Registry.register/3 function 245

Registry.start_link/1 function 244

release task 362

RELEASE_COOKIE environment variable 373

RELEASE_DISTRIBUTION environment variable 363, 367

RELEASE_NODE environment variable 363, 367

releases

contents of 364367

handling 361

OTP 361362

packaging in Docker containers 367369

using 363364

remote shell 357

remsh example 373

--remsh option 357

--remsh switch 369

replicated databases 343346

request payload 185

requests, handling in GenServer 183184

:rest_for_one restart strategy 256

:restart option 260

restarts, frequency of 237238

:rex process 336

rows

deleting 289291

inserting 289291

:rpc Erlang module 335

rpc.erl file 336

run_async/2 function 154

run_erl tool 363

runtime considerations, unlimited process mailboxes 169170

runtime errors 216221

handling 218221

runtime_tools application 372

runtime, starting 6567

RuntimeError struct 219

S

scalability 142

schedulers, inner workings of 171172

scripts, running 358360

self/0 function 147

server processes 152

features of GenServer 186189

process life cycle 189190

server-side systems 79

:set table type 284

shared-nothing concurrency 170

shells, interactive 2021

short names 327, 350

short-circuit operators 38

:shutdown option 255

SimpleRegistry.register/1 function 292

SimpleRegistry.whereis/1 function 292

:size option 308

--sname parameter 327

some_module 246

spawn_link/1 function 223

spawn/1 function 145

@spec attribute 34

special forms 63

split-brain situations 348

staircasing 15

start command 367

start_child/1 function 258259

start_iex command 367, 369

stateful server processes 152167

complex states 162166

keeping process state 157158

making state mutable 158162

registered processes 166167

stdlib application 306, 365

stop command 364

Stream functions 134

Stream module 107, 134, 137, 289

Stream.repeatedly/1 function 172

Stream.run/1 function 172

Stream.with_index/1 function 108

streams 106

String class 112

String module 76, 113

String.Chars protocol 135, 137

String.length/1 function 113

String.upcase/1 function 113

__struct__ field 123

structs 119124

Stuff Goes Bad: Erlang in Anger (Hébert) 370

sum function 31

sum server process 14

sum/1 function 97

--sup parameter 298

supervision trees

organizing 253256

registering database workers 247249

separating loosely dependent parts 240243

supervising database workers 250253

via tuples 246247

Supervisor module 182, 226, 251, 254, 267

Supervisor.child_spec/2 function 248

Supervisor.init/2 function 234

Supervisor.start_link function 226

Supervisor.start_link/2 function 226, 228, 234, 241

Supervisor.terminate_child/2 function 254

supervisors 226238

child specifications 230232

linking all processes 234237

Poolboy example application, adapting pool 307310

preparing existing code 227228

restart frequency 237238

starting process 228230

starting processes dynamically

dynamic supervision 257258

using temporary restart strategy 260261

supervising dynamic tasks 272273

supervisor behaviour 181

using callback modules 233234

web server example, starting server 312314

wrapping 233

:sys.get_state/1 function 374

:sys.replace_state/2 function 374

system behavior

analyzing 207209, 370371

logging 371373

tracing 373375

System.get_env/2 function 322

System.stop function 357

systems, running

analyzing system behavior 207209, 370371

OTP releases 361362

running scripts 358360

with Elixir tools, mix and elixir commands 356358

T

tail function calls 9699

take function 107

Task module 190, 254, 256, 267, 270

Task.async/1 function 268

Task.await/1 function 268269

Task.start_link/1 function 270, 272

Task.Supervisor wrapper 272

tasks

awaited 268270

non-awaited 270272

supervising dynamic 272273

tasks variable 269

temporary restart strategy 260261

terminate/2 function 189

test macro 199, 315

:this option 328

throw/1 function 217

tick messages 348

Time module 59, 125

:timeout message 279

:timer.tc/1 function 371

tl function 42

to_erl tool 364

to-do cache, in distributed system example 338343

to-do list example

agent-powered server 276277

analyzing process dependencies 201202

implementing cache 195198

persisting data 204207

refactoring using GenServer 180181

starting processes dynamically, testing system 261262

writing tests 198201

todo script 364

todo_server variable 163

Todo.Cache interface function 227

Todo.Cache module 229, 231

Todo.Cache supervisor 258

Todo.Cache.init/1 function 205, 241

Todo.Cache.server_process/1 function 257, 259

Todo.Database implementation 212

Todo.Database module 203, 212

Todo.Database PID 204

tracing 373375

trapping exits 224

truthiness 38

truthy values 38

try blocks 63

try special form 221

tuples 3940

supervision trees via 246247

type system

atoms 39

maps 4649

types

higher-level types 5659

immutability 4346

other built-in types 55

U

unless expression 63, 89

unless macro 62

update operation 275

update_entry operation 128

update_entry request 165

update_in/2 macro 131

use Agent expression 277

use ExUnit.Case expression 198

use GenServer function 314

use macro 182

use Plug.Router function 314

V

value message handler 160

value of variable 73

value request 159161

value/1 function 121, 161

variables

in patterns 7273

overview of 2223

via_tuple/1 function 247249

:visible option 328

visualizing systems 310311

W

web servers

handling requests 314317

reasoning about system 317321

starting 312314

when clause 83

whereis/1 function 341

with expression 9194

:worker_module option 308

workers 226

wrk tool 319