Functional Java

Retired

This book is no longer available for sale.

Functional Java

with Vavr

About the Book

About the Author

dimitris papadimitriou
dimitris papadimitriou

I have more than 14 years’ experience as full stack developer and Architect.

I Like to stay in touch with all the latest developments in the field, as well as the foundational Theoretical Computer science and algorithm Analysis and Design

https://www.linkedin.com/in/dimitrispapadimitriou/

Table of Contents

  • 1 Language Functional support
    • 1.1 Pure functions and Side effects ... 6
    • 1.2 Functional Interfaces ... 9
    • 1.3 Function Composition ... 15
    • 1.3.1 Function<,> andThen method ... 15
    • 1.3.2 BiFunction<> Composition ... 16
    • 1.3.3 Supplier<> Composition ... 17
    • 1.3.4 Consumer<> Composition ... 17
    • 1.3.5 Predicate<> Composition ... 19
    • 1.4 Vavr’s Functional Interfaces ... 20
    • 1.5 Currying and partial application ... 21
    • 1.5.1 Currying and partial application with Vavr ... 24
  • 2 Functors
    • 2.1 The Identity Functor ... 26
    • 2.2 Commutative Diagrams ... 27
    • 2.3 The Functor Laws ... 28
    • 2.4 Pattern Matching ... 30
    • 2.4.1 The Basic Functor Mechanics ... 36
    • 2.5 IO Functor, a Lazy Id Functor ... 37
    • 2.5.1 Supplier as a Functor ... 37
    • 2.6 Maybe Functor – Optional and Option ... 38
    • 2.6.1 Dealing with null ... 38
    • 2.6.2 The Null Object Design pattern ... 39
    • 2.6.3 The Functional equivalent - Maybe as Functor ... 41
    • 2.6.4 Java native Maybe aka Optional ... 43
    • 2.6.5 Maybe Functor Example with java Optional ... 44
    • 2.6.6 Maybe in Vavr aka Option ... 45
    • 2.6.7 Maybe Functor Example with Vavr Option ... 46
    • 2.7 Either Functor ... 48
    • 2.7.1 Pattern matching for Either ... 50
    • 2.7.2 Either in Vavr ... 50
    • 2.7.3 Either Functor Example ... 51
    • 2.7.4 Vavr’s pattern matching Support for Either ... 53
    • 2.7.5 Using Either for exception handling ... 54
    • 2.8 Explicitly Compositing Functor ... 56
    • 2.9 Extending CompletableFuture to Functor ... 58
    • 2.10 Combining Future and Optional - Future> ... 60
    • 2.11 Combining Future and Option - Future> ... 62
    • 2.12 Combining Future and Either - Future> ... 64
  • 3 Monads
    • 3.1 The Stream Monad ... 68
    • 3.2 Maybe Monad ... 68
    • 3.3 The Java Optional Monad Example ... 70
    • 3.3.1 Using Vavr Option ... 72
    • 3.4 Either Monad ... 72
    • 3.4.1 Using Either Monad for exception handling ... 74
    • 3.4.2 Using Either for Validation ... 75
    • 3.5 Validation Monad ... 76
    • 3.5.1 Using Validation.Apply to Collect validations ... 77
    • 3.6 CompletableFuture as Monad ... 78
    • 3.7 The CompletableFuture - Optional Monad Combination ... 80
    • 3.8 The CompletableFuture - Option Monad Combination ... 82
    • 3.9 The CompletableFuture - Either Monad Combination ... 85
  • 4 A Clean Functional Architecture Example
    • 4.1 Download and Setup the Project ... 87
    • 4.1.1 Clean Architecture with Spring Boot ... 88
    • 4.2 A Functional Applications Architecture ... 90
    • 4.3 Clean Architecture with Spring Boot and Vavr.io ... 91
    • 4.4 Web Api ... 92
    • 4.5 Domain Model ... 93
    • 4.5.1 Repositories ... 96
    • 4.6 CQRS ... 97
    • 4.7 CQRS and Mediator Design Pattern ... 99
    • 4.7.1 The Command Pattern with a Mediator ... 99
    • 4.7.2 Query Workflow ... 102
    • 4.7.3 Command Workflow ... 106

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub