ebook img

Elixir in Action PDF

385 Pages·2019·4.57 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Elixir in Action

SECOND EDITION Saša Juric´ M A N N I N G praise for the first edition Delightful and insightful ... with a ton of practical advice. — Ved Antani, Electronic Arts Outstanding coverage of Elixir’s distributed computing capabilities, with a real-world point of view. — Christopher Bailey, HotelTonight Read this book if you want to think and solve problems in the Elixir way! — Kosmas Chatzimichalis, Mach 7x Functional programming made easy. — Mohsen Mostafa Jokar, Hamshahri Probably the best introduction to Elixir and the Functional Programming. — Amazon customer A good book for experienced programmers who want to learn more about Elixir. — Amazon customer Elixir in Action Second Edition SAŠA JURIC´ MANNING Shelter ISland For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2019 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initialcaps or all caps. ∞Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Karen Miller 20 Baldwin Road Review editor: Aleksandar Dragosavljevic PO Box 761 Project manager: Vincent Nordhaus Shelter Island, NY 11964 Copy editor: Andy Carrol Proofreader: Melody Dolab Technical proofreader: Riza Fahmi Typesetter: Happenstance Type-O-Rama Cover designer: Marija Tudor ISBN 9781617295027 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – SP – 23 22 21 20 19 18 brief contents 1 ■ First steps 1 2 ■ Building blocks 16 3 ■ Control flow 63 4 ■ Data abstractions 102 5 ■ Concurrency primitives 129 6 ■ Generic server processes 159 7 ■ Building a concurrent system 179 8 ■ Fault-tolerance basics 201 9 ■ Isolating error effects 224 10 ■ Beyond GenServer 251 11 ■ Working with components 277 12 ■ Building a distributed system 305 13 ■ Running the system 334 v contents preface xiii acknowledgments xv about this book xvii about the author xxi about the cover illustration xxii 1 First steps 1 1.1 About Erlang 1 High availability 3 ■ Erlang concurrency 3 Server-side systems 5 ■ The development platform 7 1.2 About Elixir 8 Code simplification 9 ■ Composing functions 12 The big picture 13 1.3 Disadvantages 13 Speed 14 ■ Ecosystem 14 2 Building blocks 16 2.1 The interactive shell 17 2.2 Working with variables 18 2.3 Organizing your code 20 Modules 20 ■ Functions 21 ■ Function arity 25 Function visibility 26 ■ Imports and aliases 27 Module attributes 28 ■ Comments 30 vii vviiiiii contents 2.4 Understanding the type system 30 Numbers 30 ■ Atoms 31 ■ Tuples 34 ■ Lists 35 Immutability 38 ■ Maps 41 ■ Binaries and bitstrings 43 ■ Strings 44 ■ First-class functions 46 Other built-in types 49 ■ Higher-level types 50 ■ IO lists 54 2.5 Operators 55 2.6 Macros 56 2.7 Understanding the runtime 57 Modules and functions in the runtime 57 ■ Starting the runtime 59 3 Control flow 63 3.1 Pattern matching 64 The match operator 64 ■ Matching tuples 64 Matching constants 65 ■ Variables in patterns 66 Matching lists 67 ■ Matching maps 68 ■ Matching bitstrings and binaries 69 ■ Compound matches 71 General behavior 72 3.2 Matching with functions 72 Multiclause functions 73 ■ Guards 76 Multiclause lambdas 78 3.3 Conditionals 79 Branching with multiclause functions 79 ■ Classical branching constructs 81 ■ The with special form 83 3.4 Loops and iterations 86 Iterating with recursion 87 ■ Tail function calls 88 Higher-order functions 91 ■ Comprehensions 95 ■ Streams 97 4 Data abstractions 102 4.1 Abstracting with modules 104 Basic abstraction 104 ■ Composing abstractions 106 Structuring data with maps 107 ■ Abstracting with structs 108 ■ Data transparency 112 4.2 Working with hierarchical data 114 Generating IDs 115 ■ Updating entries 117 ■ Immutable hierarchical updates 119 ■ Iterative updates 121 Exercise: importing from a file 122

Description:
The Elixir language blends the battle-tested power and stability of the Erlang virtual machine with an approachable and expressive syntax. Elixir in Action, Second Edition teaches you how to use the Elixir programming language to solve the practical problems of scalability, fault tolerance, and high
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.