售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Learning Java Functional Programming
Table of Contents
Learning Java Functional Programming
Credits
About the Author
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. Getting Started with Functional Programming
Aspects of functional programming
Functions
Function composition
Fluent interfaces
Strict versus non-strict evaluation
Persistent data structures
Recursion
Parallelism
Optional and monads
Java 8's support for functional style programming
Lambda expressions
Default methods
Functional interfaces
Method and constructor references
Collections
Summary
2. Putting the Function in Functional Programming
Lambda expressions usage
Functional programming concepts in Java
High-order functions
Returning a function
First-class functions
The pure function
Support repeated execution
Eliminating dependencies between functions
Supporting lazy evaluation
Referential transparency
Closure in Java
Currying
Lambda expressions revisited
Java 8 type inference
Exception handling in lambda expressions
Functional interfaces revisited
Creating a functional interface
Common functional interfaces
Function-type functional interfaces
Predicate-type functional interfaces
Consumer-type functional interfaces
Supplier-type functional interfaces
Operator-type functional interfaces
Summary
3. Function Composition and Fluent Interfaces
Introduction to function composition
Creating composite functions prior to Java 8
Creating composite functions in Java 8
Using the Function interface for function composition
Using the Functional interface to supplement methods
Passing instances of the Functional interface
Fluent interfaces
Fluent interfaces in Java 8
Method chaining and cascading
Contrasting method cascading and fluent interfaces
Creating and using fluent interfaces
Using fluent interfaces to hide older interfaces/classes
Using fluent interfaces with the Properties class
Extending fluent interfaces
Default methods and functions
Static default methods
Default methods in Java 8
Multiple inheritance in Java 8
Summary
4. Streams and the Evaluation of Expressions
The Stream class and its use
Intermediate and terminal methods
Creating streams
Fixed length streams
Infinite streams
Using the iterate method to create an infinite stream
Using the generate method to create an infinite stream
Using the Stream class methods
Filter methods
Using the filter method
Using the skip method
Sorting streams
Mapping methods
Understanding the mapping operation
Implementing the map-reduce paradigm
Using the flatmap method
Lazy and eager evaluation
Stream and concurrent processing
Understanding non-inference
Understanding stateless operations
Understanding side effects
Understanding the ordering
Summary
5. Recursion Techniques in Java 8
Recursive data structures
Types of recursion
Using direct recursion
Head and tail recursion
Understanding recursion
The Node class
Using head recursion
Using tail recursion
Using the head and tail recursion
Creating a recursive solution based on a formula
Converting an iterative loop to a recursive solution
Merging two lists
Understanding the program stack
Recursive lambda expressions
Common problems found in recursive solutions
Absence of a base case
Using static or instance variables
Using the pre- and post-increment operators
Recursion implementation techniques
Using a wrapper method
Using short circuiting
Tail call optimization
Converting to a tail call
When to use recursion
Recursion and humor
Summary
6. Optional and Monads
Using the Optional class
Creating Optional instances
Using the Optional class to support return values
Handling missing values
Using the orElse method to get a substitute value
Using the orElseGet method to use a function to get a substitute value
Using the orElseThrow method to throw an exception
Filter and transforming values
Using the Optional class's filter method
Using the Optional class's map method
Optional solution to the Customer problem
Disadvantages of the Optional class
Monads
Monads in Java 8
Using the of method as the unit function
Using the flatMap method
Using the map method
Using the Optional class with strings
Using monads with the Part class
A formal discussion of monads
Associativity
Left identity
Right identity
Summary
7. Supporting Design Patterns Using Functional Programming
Implementing the execute-around-method pattern
Object-oriented solution to the execute-around-method pattern
Functional solution to the execute-around-method pattern
Using the execute-around-method pattern with a stream
Implementing the factory pattern
Object-oriented solution to the factory pattern
Functional solution to the factory pattern
Implementing the command pattern
Object-oriented solution to the command pattern
Functional solution to the command pattern
Implementing the strategy pattern
Object-oriented solution to strategy pattern
Functional solution to the strategy pattern
Using the Function interface
Implementing the visitor pattern
Object-orient solution to the visitor pattern
Functional solution to the visitor pattern
Implementing the template pattern
Object-oriented solution to the template pattern
Functional solution to the template pattern
Summary
8. Refactoring, Debugging, and Testing
Refactoring functional code
NetBeans support for refactoring
Converting anonymous inner classes to lambda expressions
Refactoring multiple code instances
Support of other refactoring operations
Eclipse support for refactoring
Converting anonymous inner classes to lambda expressions
Refactoring multiple code instances
Support of other refactoring operations
Debugging lambda expressions
Using the println method to assist debugging
Using the peek method to assist debugging
Debugging lambda expressions using NetBeans
Debugging lambda expressions using Eclipse
Debugging recursive lambda expressions
Debugging parallel streams
Testing functional programs
Testing lambda expressions
Copying the lambda expression
Using a method reference
Reorganizing the test class
Testing exceptions using a fluent style
Summary
9. Bringing It All Together
Functional Zork
Playing the game
The game's architecture
Understanding the GameElements class
Introducing the Item, Direction, and NPC classes
Implementing the FunctionalZork class
Initializing the game
Initializing the commands
Getting a command from the console
Parsing the command
Executing the command
Implementing the Character class
Implementing the pickup method
Implementing the drop method
Implementing the walk method
Implementing the inventory method
Implementing the Location class
Handling items
Handling NPCs
Handling directions
Summary
Epilogue
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜