售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Scala Functional Programming Patterns
Table of Contents
Scala Functional Programming Patterns
Credits
About the Author
Aknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Grokking the Functional Way
Abstractions
Concise expression
Functions
Immutable
Referential transparency
The problem – grouping continuous integers
Java code
Going scalaish
Thinking recursively...
Reusability – the commonality/variability analysis
The one-liner shockers
Scala idioms
Patterns and those aha! moments
The command design pattern
The strategy design pattern
Passing algorithms around
Summary
2. Singletons, Factories, and Builders
Singletons – being one and only one
Null Objects – singletons in another garb
Null Objects – the Scala way
Options are container
Scala singletons
The apply() factory method
The factory method pattern
The Scala version
Builders
Ease of object creation
Scala shines again
Summary
3. Recursion and Chasing your Own Tail
Recursive structures
Pattern matching
Deconstruction with case statements
Stack overflows
Tail recursion to the rescue
Getting the nth element of a list
An expression parser
Persistent data structures
Two forms of recursion
Summary
4. Lazy Sequences – Being Lazy, Being Good
Illusion and reality – the proxy pattern
Hibernate's lazy loading
Lazy val – calling by need
Infinite sequences – Scala streams
Recursive streams
Memoization and the flyweight pattern
Call by name
Streams are collections
Sieve of Eratosthenes
A view to a collection
Summary
5. Taming Multiple Inheritance with Traits
The iterator design pattern
Interfaces as types
The dreaded diamond
Traits – Scala's rich interfaces
Mix-ins – rich interfaces
Frills and thrills – the decorator pattern
Scala's easy and breezy decorations – stackable modifications
Dependencies injection pattern
A taste of the cake pattern
Sealed traits
Defeating the dreaded diamond
Summary
6. Currying Favors with Your Code
Functions as first-class values
Roping in a scope
Local functions – hiding and biding their time
The underscore – Scala's Swiss army knife
A taste of the curry
Type inference
Of implicits and explicits
Stylish blocks
The loan pattern
Serving the curry
Frills and thrills – decorators again
Wrapping it up
Summary
7. Of Visitors and Chains of Responsibilities
A tale of two hierarchies
The Visitor pattern
Many hues of pattern matching
De-structuring
Typed patterns
Pattern guards
Tuple explosion
Partial functions
Visitor pattern – the Scala way
Lifting it up
The chain of responsibility
Scalaish Chain Of Responsibilities
Match and mismatch – the collect idiom
Summary
8. Traversals – Mapping/Filtering/Folding/Reducing
Iterating the Scala way
A validation problem
Setting the stage
First cut–using arrays
Second cut–using a map
Third cut–using a for expression
Fourth cut–using foldLeft
Fifth cut–using andThen
Sixth cut–using compose
Foreach–sugary sweetener
One generator
A generator and a filter
Two generators
Monads
Reduce
Summary
9. Higher Order Functions
The strategy design pattern
A strategy in Scala land
Functors
Maps
Monads
FlatMap
Monoids
An inverted index
Pipes and filters
Pipes and filters – the Scala version
It is a Monoid
Lazy collections
Summary
10. Actors and Message Passing
The recursive grep
The producer/consumer pattern
Threads – masters and slaves
Events
Immutability is golden
Akka actors take the stage
Summary
11. It's a Paradigm Shift
Verbosity
Sorting it out!
Sorted
SortBy
SortWith
Scalaish Schwartzian transform
Functional error handling
Pattern matching
Threads and futures
Scala's Futures
Parser combinators
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜