Scala for the Impatient

Scala for the Impatient

  • ただいまウェブストアではご注文を受け付けておりません。 ⇒古書を探す
  • 製本 Paperback:紙装版/ペーパーバック版/ページ数 360 p.
  • 言語 ENG
  • 商品コード 9780321774095
  • DDC分類 005.133

Full Description


Scala is a modern programming language for the Java Virtual Machine (JVM) that combines the best features of object-oriented and functional programming languages. Using Scala, you can write programs more concisely than in Java, as well as leverage the full power of concurrency. Since Scala runs on the JVM, it can access any Java library and is interoperable with Java frameworks. Scala for the Impatient concisely shows developers what Scala can do and how to do it. In this book, Cay Horstmann, the principal author of the international best-selling Core Java (TM), offers a rapid, code-based introduction that's completely practical. Horstmann introduces Scala concepts and techniques in "blog-sized" chunks that you can quickly master and apply. Hands-on activities guide you through well-defined stages of competency, from basic to expert. Coverage includes Getting started quickly with Scala's interpreter, syntax, tools, and unique idioms Mastering core language features: functions, arrays, maps, tuples, packages, imports, exception handling, and more Becoming familiar with object-oriented programming in Scala: classes, inheritance, and traits Using Scala for real-world programming tasks: working with files, regular expressions, and XML Working with higher-order functions and the powerful Scala collections library Leveraging Scala's powerful pattern matching and case classes Creating concurrent programs with Scala actors Implementing domain-specific languages Understanding the Scala type system Applying advanced "power tools" such as annotations, implicits, and delimited continuations Scala is rapidly reaching a tipping point that will reshape the experience of programming. This book will help object-oriented programmers build on their existing skills, allowing them to immediately construct useful applications as they gradually master advanced programming techniques.

Contents

Foreword xviiPreface xixAbout the Author xxi Chapter 1The Scala Interpreter 11.2 Declaring Values and Variables 31.3 Commonly Used Types 41.4 Arithmetic and Operator Overloading 51.5 Calling Functions and Methods 71.6 The apply Method 81.7 Scaladoc 8Exercises 11 Chapter 2: Control Structures and Functions 132.1 Conditional Expressions 142.2 Statement Termination 152.3 Block Expressions and Assignments 162.4 Input and Output 172.5 Loops 182.6 Advanced for Loops and for Comprehensions 192.7 Functions 202.8 Default and Named Arguments 212.9 Variable Arguments 222.10 Procedures 232.11 Lazy Values 232.12 Exceptions 24Exercises 26 Chapter 3: Working with Arrays 293.1 Fixed-Length Arrays 293.2 Variable-Length Arrays: Array Buffers 303.3 Traversing Arrays and Array Buffers 313.4 Transforming Arrays 323.5 Common Algorithms 343.6 Deciphering Scaladoc 353.7 Multidimensional Arrays 373.8 Interoperating with Java 37Exercises 38 Chapter 4: Maps and Tuples 414.1 Constructing a Map 414.2 Accessing Map Values 424.3 Updating Map Values 434.4 Iterating over Maps 434.5 Sorted Maps 444.6 Interoperating with Java 444.7 Tuples 454.8 Zipping 46Exercises 46 Chapter 5: Classes 495.1 Simple Classes and Parameterless Methods 495.2 Properties with Getters and Setters 505.3 Properties with Only Getters 535.4 Object-Private Fields 545.5 Bean Properties 555.6 Auxiliary Constructors 565.7 The Primary Constructor 575.8 Nested Classes 60Exercises 63 Chapter 6: Objects 656.1 Singletons 656.2 Companion Objects 666.3 Objects Extending a Class or Trait 676.4 The apply Method 676.5 Application Objects 686.6 Enumerations 69Exercises 71 Chapter 7: Packages and Imports 737.1 Packages 747.2 Scope Rules 757.3 Chained Package Clauses 777.4 Top-of-File Notation 777.5 Package Objects 787.6 Package Visibility 787.7 Imports 797.8 Imports Can Be Anywhere 807.9 Renaming and Hiding Members 807.10 Implicit Imports 80Exercises 81 Chapter 8: Inheritance 858.1 Extending a Class 858.2 Overriding Methods 868.3 Type Checks and Casts 878.4 Protected Fields and Methods 888.5 Superclass Construction 888.6 Overriding Fields 898.7 Anonymous Subclasses 918.8 Abstract Classes 918.9 Abstract Fields 918.10 Construction Order and Early Definitions 928.11 The Scala Inheritance Hierarchy 948.12 Object Equality 95Exercises 96 Chapter 9: Files and Regular Expressions 999.1 Reading Lines 1009.2 Reading Characters 1009.3 Reading Tokens and Numbers 1019.4 Reading from URLs and Other Sources 1029.5 Reading Binary Files 1029.6 Writing Text Files 1029.7 Visiting Directories 1039.8 Serialization 1049.9 Process Control 1059.10 Regular Expressions 1069.11 Regular Expression Groups 107Exercises 107 Chapter 10: Traits 11110.1 Why No Multiple Inheritance? 11110.2 Traits as Interfaces 11310.3 Traits with Concrete Implementations 11410.4 Objects with Traits 11510.5 Layered Traits 11610.6 Overriding Abstract Methods in Traits 11710.7 Traits for Rich Interfaces 11810.8 Concrete Fields in Traits 11810.9 Abstract Fields in Traits 11910.10 Trait Construction Order 12010.11 Initializing Trait Fields 12210.12 Traits Extending Classes 12310.13 Self Types 12410.14 What Happens under the Hood 125Exercises 127 Chapter 11: Operators 13111.1 Identifiers 13111.2 Infix Operators 13211.3 Unary Operators 13311.4 Assignment Operators 13311.5 Precedence 13411.6 Associativity 13511.7 The apply and update Methods 13511.8 Extractors 13611.9 Extractors with One or No Arguments 13811.10 The unapplySeq Method 138Exercises 139 Chapter 12: Higher-Order Functions 14312.1 Functions as Values 14312.2 Anonymous Functions 14412.3 Functions with Function Parameters 14512.4 Parameter Inference 14612.5 Useful Higher-Order Functions 14612.6 Closures 14812.7 SAM Conversions 14912.8 Currying 14912.9 Control Abstractions 15012.10 The return Expression 152Exercises 152 Chapter 13: Collections 15513.1 The Main Collections Traits 15613.2 Mutable and Immutable Collections 15713.3 Sequences 15813.4 Lists 15913.5 Mutable Lists 16013.6 Sets 16113.7 Operators for Adding or Removing Elements 16213.8 Common Methods 16413.9 Mapping a Function 16713.10 Reducing, Folding, and Scanning 16813.11 Zipping 17113.12 Iterators 17213.13 Streams 17313.14 Lazy Views 17413.15 Interoperability with Java Collections 17513.16 Threadsafe Collections 17713.17 Parallel Collections 178Exercises 179 Chapter 14: Pattern Matching and Case Classes 18314.1 A Better Switch 18414.2 Guards 18514.3 Variables in Patterns 18514.4 Type Patterns 18614.5 Matching Arrays, Lists, and Tuples 18714.6 Extractors 18814.7 Patterns in Variable Declarations 18814.8 Patterns in for Expressions 18914.9 Case Classes 18914.10 The copy Method and Named Parameters 19014.11 Infix Notation in case Clauses 19114.12 Matching Nested Structures 19214.13 Are Case Classes Evil? 19214.14 Sealed Classes 19314.15 Simulating Enumerations 19414.16 The Option Type 19414.17 Partial Functions 195Exercises 196 Chapter 15: Annotations 19915.1 What Are Annotations? 20015.2 What Can Be Annotated? 20015.3 Annotation Arguments 20115.4 Annotation Implementations 20215.5 Annotations for Java Features 20315.6 Annotations for Optimizations 20615.7 Annotations for Errors and Warnings 210Exercises 211 Chapter 16: XML Processing 21316.1 XML Literals 21416.2 XML Nodes 21416.3 Element Attributes 21616.4 Embedded Expressions 21716.5 Expressions in Attributes 21816.6 Uncommon Node Types 21916.7 XPath-like Expressions 22016.8 Pattern Matching 22116.9 Modifying Elements and Attributes 22216.10 Transforming XML 22316.11 Loading and Saving 22316.12 Namespaces 226Exercises 227 Chapter 17: Type Parameters 23117.1 Generic Classes 23217.2 Generic Functions 23217.3 Bounds for Type Variables 23217.4 View Bounds 23417.5 Context Bounds 23417.6 The Manifest Context Bound 23517.7 Multiple Bounds 23517.8 Type Constraints 23617.9 Variance 23717.10 Co- and Contravariant Positions 23817.11 Objects Can't Be Generic 24017.12 Wildcards 241Exercises 241 Chapter 18: Advanced Types 24518.1 Singleton Types 24618.2 Type Projections 24718.3 Paths 24818.4 Type Aliases 24918.5 Structural Types 25018.6 Compound Types 25018.7 Infix Types 25118.8 Existential Types 25218.9 The Scala Type System 25318.10 Self Types 25418.11 Dependency Injection 25518.12 Abstract Types 25718.13 Family Polymorphism 25918.14 Higher-Kinded Types 263Exercises 265 Chapter 19: Parsing 26919.1 Grammars 27019.2 Combining Parser Operations 27119.3 Transforming Parser Results 27319.4 Discarding Tokens 27419.5 Generating Parse Trees 27519.6 Avoiding Left Recursion 27619.7 More Combinators 27719.8 Avoiding Backtracking 28019.9 Packrat Parsers 28019.10 What Exactly Are Parsers? 28119.11 Regex Parsers 28219.12 Token-Based Parsers 28319.13 Error Handling 285Exercises 286 Chapter 20: Actors 28920.1 Creating and Starting Actors 29020.2 Sending Messages 29120.3 Receiving Messages 29220.4 Sending Messages to Other Actors 29320.5 Channels 29420.6 Synchronous Messages and Futures 29520.7 Thread Sharing 29620.8 The Actor Life Cycle 29920.9 Linking Actors 30020.10 Designing with Actors 301Exercises 302 Chapter 21: Implicits 30521.1 Implicit Conversions 30621.2 Using Implicits for Enriching Existing Libraries 30621.3 Importing Implicits 30721.4 Rules for Implicit Conversions 30821.5 Implicit Parameters 30921.6 Implicit Conversions with Implicit Parameters 31021.7 Context Bounds 31121.8 Evidence 31221.9 The @implicitNotFound Annotation 31321.10 CanBuildFrom Demystified 314Exercises 316 Chapter 22: Delimited Continuations 31922.1 Capturing and Invoking a Continuation 32022.2 The "Computation with a Hole" 32122.3 The Control Flow of reset and shift 32222.4 The Value of a reset Expression 32322.5 The Types of reset and shift Expressions 32322.6 CPS Annotations 32522.7 Turning a Recursive Visit into an Iteration 32622.8 Undoing Inversion of Control 32922.9 The CPS Transformation 33222.10 Transforming Nested Control Contexts 334Exercises 336 Index 339