万本电子书0元读

万本电子书0元读

顶部广告

Learning Java Functional Programming电子书

售       价:¥

11人正在读 | 0人评论 9.8

作       者:Richard M Reese

出  版  社:Packt Publishing

出版时间:2015-10-14

字       数:262.7万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Create robust and maintainable Java applications using the functional style of programmingAbout This BookExplore how you can blend object-oriented and functional programming styles in JavaUse lambda expressions to write flexible and succinct codeA tutorial that strengthens your fundamentals in functional programming techniques to enhance your applications Who This Book Is For If you are a Java developer with object-oriented experience and want to use a functional programming approach in your applications, then this book is for you. All you need to get started is familiarity with basic Java object-oriented programming concepts.What You Will LearnUse lambda expressions to simplyfy codeUse function composition to achieve code fluencyApply streams to simply implementations and achieve parallelismIncorporate recursion to support an application’s functionalityProvide more robust implementations using OptionalsImplement design patterns with less codeRefactor object-oriented code to create a functional solutionUse debugging and testing techniques specific to functional programs In Detail Functional programming is an increasingly popular technology that allows you to simplify many tasks that are often cumbersome and awkward using an object-oriented approach. It is important to understand this approach and know how and when to apply it. Functional programming requires a different mindset, but once mastered it can be very rewarding. This book simplifies the learning process as a problem is described followed by its implementation using an object-oriented approach and then a solution is provided using appropriate functional programming techniques. Writing succinct and maintainable code is facilitated by many functional programming techniques including lambda expressions and streams. In this book, you will see numerous examples of how these techniques can be applied starting with an introduction to lambda expressions. Next, you will see how they can replace older approaches and be combined to achieve surprisingly elegant solutions to problems. This is followed by the investigation of related concepts such as the Optional class and monads, which offer an additional approach to handle problems. Design patterns have been instrumental in solving common problems. You will learn how these are enhanced with functional techniques. To transition from an object-oriented approach to a functional one, it is useful to have IDE support. IDE tools to refactor, debug, and test functional programs are demonstrated through the chapters. The end of the book brings together many of these functional programming techniques to create a more comprehensive application. You will find this book a very useful resource to learn and apply functional programming techniques in Java.Style and approach In this tutorial, each chapter starts with an introduction to the terms and concepts covered in that chapter. It quickly progresses to contrast an object-oriented approach with a functional approach using numerous code examples.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部