Functional Programming in Java: Harness the Power of Streams and Lambda Expressions. 2 Ed

Functional Programming in Java: Harness the Power of Streams and Lambda Expressions. 2 Ed

Functional Programming in Java: Harness the Power of Streams and Lambda Expressions. 2 Ed
Автор: Subramaniam Venkat
Дата выхода: 2023
Издательство: The Pragmatic Programmers, LLC.
Количество страниц: 387
Размер файла: 1,4 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Foreword to the First Edition
Acknowledgments
Preface
Who’s This Book For
What’s in This Book
Java Version Used in This Book
How to Read the Code Examples
Online Resources
1. Hello, Lambda Expressions!
Change the Way You Think
The Big Gains of Functional-Style Code
Why Code in the Functional Style?
Evolution, Not Revolution
A Little Sugar to Sweeten
Wrapping Up
2. Using Collections
Iterating through a List
Transforming a List
Finding Elements
Skipping Values
Terminating Iterations
Reusing Lambda Expressions
Using Lexical Scoping and Closures
Picking an Element
Reducing a Collection to a Single Value
Joining Elements
Wrapping Up
3. Strings, Comparators, and Filters
Iterating a String
Implementing the Comparator Interface
Multiple and Fluent Comparisons
Using the collect Method and the Collectors Class
Listing All Files in a Directory
Listing Select Files in a Directory
Listing Immediate Subdirectories Using flatMap
Watching a File Change
Wrapping Up
4. Transforming Data
Computing Statistics
When to Use map vs. flatMap
Checking for Criteria
Partitioning a Collection
Counting Occurrences
Summing Values
Using flatMapping and filtering
Teeing Operations
Wrapping Up
5. Designing with Lambda Expressions
Separating Concerns Using Lambda Expressions
Delegating Using Lambda Expressions
Decorating Using Lambda Expressions
A Peek into the default Methods
Creating Fluent Interfaces Using Lambda Expressions
Wrapping Up
6. Working with Resources
Cleaning Up Resources
Using the Execute Around Method Pattern to Clean Up Resources
Managing Locks
Creating Concise Exception Tests
Wrapping Up
7. Being Lazy
Delayed Initialization
Lazy Evaluations
Leveraging the Laziness of Streams
Creating Infinite, Lazy Collections
Wrapping Up
8. Optimizing Recursions
Using Tail-Call Optimization
Speeding Up with Memoization
Wrapping Up
9. Composing Functions with Lambda Expressions
Using Function Composition
Using MapReduce
Taking a Leap to Parallelize
Wrapping Up
10. Error Handling
Taking a Holistic View of Error Handling
Exception Handling and Imperative Style
Checked Exceptions and Functional Style with Streams
Exception Handling vs. Functional Style
Dealing with It Downstream
Handling Failures in Functional Programming
Wrapping Up
11. Refactoring to Functional Style
Creating a Safety Net for Refactoring
Refactoring the Traditional for Loop
Refactoring More Complex Loops
Refactoring Unbounded Loops
Refactoring for-each
Refactoring to Rework the Logic
Refactoring File Processing
Refactoring Data Grouping Operations
Refactoring Nested Loops
Real-World Refactoring
Wrapping Up
12. Functional Programming Idioms
Don’t Write Dense Lambda Expressions
Prefer Method References
Properly Structure the Functional Pipeline
Keep Separate Conditions in Separate Filters
Provide Good Domain-Specific Parameter Names
Use Type Inference for Parameters
Side Effects in Functional Pipelines
Wrapping Up
13. Bringing It All Together
Essential Practices to Succeed with the Functional Style
Performance Concerns
Adopting the Functional Style
A1. Starter Set of Functional Interfaces
A2. Syntax Overview
A3. Web Resources
Bibliography

The new features introduced in Java 8 were designed together to facilitate development of more expressive and parallel-friendly libraries.
Lambda expressions reduce the syntactic overhead of encoding behavior as data; default methods allow existing libraries to evolve over time, enabling core JDK classes such as Collections to take advantage of lambda expressions; the java.util.stream package leverages these language features to offer rich aggregate operations on collections, arrays, and other data sources in a declarative, expressive, and parallel-friendly manner.
All of this adds up to more powerful and performant code, as well as a more pleasant programming experience.
This book not only provides lots of examples of how to use these new features, but offers readers a peek into the underlying principles behind their design, and why they result in better code. Let Venkat be your guide to this new and improved Java—you’re in for a treat.


Похожее:

Список отзывов:

Нет отзывов к книге.