Learning Scala: Practical Functional Programming for the JVM

Купить бумажную книгу и читать

Купить бумажную книгу

По кнопке выше можно купить бумажные варианты этой книги и похожих книг на сайте интернет-магазина "Лабиринт".

Using the button above you can buy paper versions of this book and similar books on the website of the "Labyrinth" online store.

Реклама. ООО "ЛАБИРИНТ.РУ", ИНН: 7728644571, erid: LatgCADz8.

Автор: Jason Swartz

Название: Learning Scala: Practical Functional Programming for the JVM

Язык: English

Издательство: Sebastopol, CA : O'Reilly Media

Год: 2014

Формат: pdf

Размер: 15,4 mb

Страниц: 256

Why learn Scala? You don’t need to be a data scientist or distributed computing expert to appreciate this object-oriented functional programming language. This practical book provides a comprehensive yet approachable introduction to the language, complete with syntax diagrams, examples, and exercises. You’ll start with Scala's core types and syntax before diving into higher-order functions and immutable data structures.

Author Jason Swartz demonstrates why Scala’s concise and expressive syntax make it an ideal language for Ruby or Python developers who want to improve their craft, while its type safety and performance ensures that it’s stable and fast enough for any application.

Learn about the core data types, literals, values, and variables

Discover how to think and write in expressions, the foundation for Scala's syntax

Write higher-order functions that accept or return other functions

Become familiar with immutable data structures and easily transform them with type-safe and declarative operations

Create custom infix operators to simplify existing operations or even to start your own domain-specific language

Build classes that compose one or more traits for full reusability, or create new functionality by mixing them in at instantiation

 

Preface.............................................................................. ix

Part I. Core Scala

1. Getting Started with the Scalable Language................................3

Installing Scala 3

Using the Scala REPL 4

Summary 6

Exercises 6

2. Working with data: Literals, Values, Variables, and Types................9

Values 10

Variables 12

Naming 13

Types 15

Numeric Data Types 15

Strings 17

An Overview of Scala Types 21

Tiiples 25

Summary 26

Exercises 26

3. Expressions and Conditionals............................................27

Expressions 27

Defining Values and Variables with Expressions 28

Expression Blocks 28

Statements 29

If-Else Expression Blocks 30

If Expressions 30

If-Else Expressions 31

Match Expressions 31

Matching with Wildcard Patterns 34

Matching with Pattern Guards 36

Matching Types with Pattern Variables 36

Loops 37

Iterator Guards 39

Nested Iterators 39

Value Binding 40

While and DoAVhile Loops 40

Summary 41

Exercises 42

4. Functions.............................................................. 45

Procedures 48

Functions with Empty Parentheses 48

Function Invocation with Expression Blocks 49

Recursive Functions 50

Nested Functions 52

Calling Functions with Named Parameters 53

Parameters with Default Values 53

Vararg Parameters 54

Parameter Groups 55

Type Parameters 55

Methods and Operators 57

Writing Readable Functions 60

Summary 62

Exercises 62

5. First-Class Functions.................................................. 65

Function Types and Values 66

Higher-Order Functions 68

Function Literals 69

Placeholder Syntax 72

Partially Applied Functions and Currying 74

By-Name Parameters 75

Partial Functions 76

Invoking Higher-Order Functions with Function Literal Blocks 78

Summary 80

Exercises 81

6. Common Collections 83

Lists, Sets, and Maps 83

Whats in a List? 86

The Cons Operator 89

List Arithmetic 90

Mapping Lists 92

Reducing Lists 93

Converting Collections 98

Java and Scala Collection Compatibility 99

Pattern Matching with Collections 100

Summary 101

Exercises 102

7. More Collections 107

Mutable Collections 107

Creating New Mutable Collections 108

Creating Mutable Collections from Immutable Ones 109

Using Collection Builders 111

Arrays 112

Seq and Sequences 113

Streams 115

Monadic Collections 117

Option Collections 117

Try Collections 121

Future Collections 125

Summary 130

Exercises 131

Part II. Object-Oriented Scala

Classes 137

Defining Classes 142

More Class Types 146

Abstract Classes 146

Anonymous Classes 148

More Field and Method Types 149

Overloaded Methods 149

Apply Methods 150

Lazy Values 150

Packaging 151

Accessing Packaged Classes 152

Packaging Syntax 156

Privacy Controls 158

Privacy Access Modifiers 160

Final and Sealed Classes 161

Summary 162

Exercises 162

Objects, Case (lasses, and Traits 167

Objects 167

Apply Methods and Companion Objects 169

Command-Line Applications with Objects 172

Case Classes 173

Traits 176

Self Types 180

Instantiation with Traits 182

Importing Instance Members 184

Summary 185

Break—Configuring Your First Scala Project 186

Exercises 191

Advanced Typing 199

Tuple and Function Value Classes 201

Implicit Parameters 203

Implicit Classes 205

Types 207

Type Aliases 207

Abstract Types 208

Bounded Types 209

Type Variance 212

Package Objects 216

Summary 217

Questions 218

Reserved Words 221

Index,

225

Дата создания страницы: