BigJoe Logo BigJoe
Blog Books
Blog Books
All Books Functional Programming in Scala, Second Edition Draft
All Books
Functional Programming in Scala, Second Edition

Functional Programming in Scala, Second Edition Draft

Michael Pilquist, Rúnar Bjarnason, Paul Chiusano

Contents

Jump to chapter

1. front matter: foreword to the first edition 1.1 foreword to the first edition 1.2 foreword to the second edition 1.3 preface to the second edition 1.4 acknowledgments 1.5 about this book 1.6 about the authors
2. Part 1. Introduction to functional programming
3. 1 What is functional programming? 3.1 1.1 Understanding the benefits of functional programming 3.2 1.2 Exactly what is a (pure) function? 3.3 1.3 Referential transparency, purity, and the substitution model 3.4 1.4 Conclusion 3.5 Summary
4. 2 Getting started with functional programming in Scala 4.1 2.1 Introducing Scala the language 4.2 2.2 Objects and namespaces 4.3 2.3 Higher-order functions: Passing functions to functions 4.4 2.4 Polymorphic functions: Abstracting over types 4.5 2.5 Following types to implementations 4.6 2.6 Conclusion 4.7 Summary 4.8 2.7 Exercise answers
5. 3 Functional data structures 5.1 3.1 Defining functional data structures 5.2 3.2 Pattern matching 5.3 3.3 Data sharing in functional data structures 5.4 3.4 Trees 5.5 3.5 Conclusion 5.6 Summary 5.7 3.6 Exercise answers
6. 4 Handling errors without exceptions 6.1 4.1 The good and bad aspects of exceptions 6.2 4.2 Possible alternatives to exceptions 6.3 4.3 The Option data type 6.4 4.4 The Either data type 6.5 4.5 Conclusion 6.6 Summary 6.7 4.6 Exercise answers
7. 5 Strictness and laziness 7.1 5.1 Strict and nonstrict functions 7.2 5.2 Lazy lists: An extended example 7.3 5.3 Separating program description from evaluation 7.4 5.4 Infinite lazy lists and corecursion 7.5 5.5 Conclusion 7.6 Summary 7.7 5.6 Exercise answers
8. 6 Purely functional state 8.1 6.1 Generating random numbers using side effects 8.2 6.2 Purely functional random number generation 8.3 6.3 Making stateful APIs pure 8.4 6.4 A better API for state actions 8.5 6.5 A general state action data type 8.6 6.6 Purely functional imperative programming 8.7 6.7 Conclusion 8.8 Summary 8.9 6.8 Exercise Answers
9. Part 2. Functional design and combinator libraries
10. 7 Purely functional parallelism 10.1 7.1 Choosing data types and functions 10.2 7.2 Picking a representation 10.3 7.3 The algebra of an API 10.4 7.4 Refining combinators to their most general form 10.5 7.5 Conclusion 10.6 Summary 10.7 7.9 Exercise answers
11. 8 Property-based testing 11.1 8.1 A brief tour of property-based testing 11.2 8.2 Test case minimization 11.3 8.3 Testing higher-order functions and future directions 11.4 8.4 The laws of generators 11.5 8.5 Conclusion 11.6 Summary 11.7 8.6 Exercise answers
12. 9 Parser combinators 12.1 9.1 Designing an algebra first 12.2 9.2 A possible algebra 12.3 9.3 Handling context sensitivity 12.4 9.4 Writing a JSON parser 12.5 9.5 Error reporting 12.6 9.6 Implementing the algebra 12.7 9.7 Conclusion 12.8 Summary 12.9 9.8 Exercise answers
13. Part 3. Common structures in functional design
14. 10 Monoids 14.1 10.1 What is a monoid? 14.2 10.2 Folding lists with monoids 14.3 10.3 Associativity and parallelism 14.4 10.4 Example: Parallel parsing 14.5 10.5 Typeclasses 14.6 10.6 Foldable data structures 14.7 10.7 Composing monoids 14.8 10.8 Conclusion 14.9 Summary 14.10 10.9 Exercise answers
15. 11 Monads 15.1 11.1 Functors: Generalizing the map function 15.2 11.2 Monads: Generalizing the flatMap and unit functions 15.3 11.3 Monadic combinators 15.4 11.4 Monad laws 15.5 11.5 Just what is a monad? 15.6 11.6 Conclusion 15.7 Summary 15.8 11.7 Exercise answers
16. 12 Applicative and traversable functors 16.1 12.1 Generalizing monads 16.2 12.2 The Applicative trait 16.3 12.3 The difference between monads and applicative functors 16.4 12.4 The advantages of applicative functors 16.5 12.5 The applicative laws 16.6 12.6 Traversable functors 16.7 12.7 Uses of Traverse 16.8 12.8 Conclusion 16.9 Summary 16.10 12.9 Exercise answers
17. Part 4. Effects and I/O
18. 13 External effects and I/O 18.1 13.1 Factoring effects 18.2 13.2 A simple IO type 18.3 13.3 Avoiding the StackOverflowError 18.4 13.4 A more nuanced I/O type 18.5 13.5 Non-blocking and asynchronous I/O 18.6 13.6 Capabilities 18.7 13.7 A general-purpose I/O type 18.8 13.8 Why the IO type is insufficient for streaming I/O 18.9 13.9 Conclusion 18.10 Summary 18.11 13.10 Exercise answers
19. 14 Local effects and mutable state 19.1 14.1 Purely functional mutable state 19.2 14.2 A data type to enforce the scoping of side effects 19.3 14.3 Purity is contextual 19.4 14.4 Conclusion 19.5 Summary 19.6 14.5 Exercise answers
20. 15 Stream processing and incremental I/O 20.1 15.1 Problems with imperative I/O: An example 20.2 15.2 Simple stream transformations 20.3 15.3 Extensible pulls and streams 20.4 15.4 Applications 20.5 15.5 Conclusion 20.6 Summary 20.7 15.6 Exercise answers
Font size
Background
Font

front matter: foreword to the first edition

foreword to the first edition