Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java Functional Programming

You're reading from   Learning Java Functional Programming Create robust and maintainable Java applications using the functional style of programming

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783558483
Length 296 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Richard M. Reese Richard M. Reese
Author Profile Icon Richard M. Reese
Richard M. Reese
Richard M Reese Richard M Reese
Author Profile Icon Richard M Reese
Richard M Reese
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with Functional Programming 2. Putting the Function in Functional Programming FREE CHAPTER 3. Function Composition and Fluent Interfaces 4. Streams and the Evaluation of Expressions 5. Recursion Techniques in Java 8 6. Optional and Monads 7. Supporting Design Patterns Using Functional Programming 8. Refactoring, Debugging, and Testing 9. Bringing It All Together Index

Creating composite functions prior to Java 8


Prior to Java 8 it was possible to affect this type of operation using a specialized library such as http://www.functionaljava.org/ or by creating a class and interface first. We will demonstrate the latter approach here.

The interface will permit two methods to be combined. To illustrate this approach, we will declare a class called Compose. Within the class, we will declare a CompositionFunction interface, containing a single call method along with a compose method. The compose method returns an instance of the CompositionFunction interface using two CompositionFunction interface instances passed to it. The call method does the actual work.

The first part of the Compose class and the CompositionFunction interface are shown next. This interface uses generics to declare a single method, call, that is passed a single value and returns a value:

public class Compose {
    public interface CompositionFunction<T, R> {
        R call(T x);
    }...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime