Grokking FRP
Timo Tuominen
  • MEAP began June 2016
  • Publication in August 2017 (estimated)
  • ISBN 9781617293368
  • 325 pages (estimated)
  • printed in black & white

In today's world, user interfaces have to be highly dynamic, asynchronous, and reliable. To meet these demands, the programming world is undergoing a radical shift in thinking about how applications should be designed. This change is called Functional Reactive Programming (FRP), or just Reactive Programming. FRP offers you a new way to construct your application so it responds directly to change. Embracing FRP lets you spend less time tracing obscure problems and more time focusing on what your code should be doing. Changing to an FRP way of thinking can be tough, and that's where this book can help.

Grokking FRP teaches you a new way of thinking about programs and data as well as how to build robust and extensible user interfaces. This well-illustrated book presents lots of concrete, real-world problems and then shows you how FRP helps you solve them. You'll begin by looking at examples that get you into the mindset of data flows. Then this book introduces the concept of a View Model and explains how it can be used as a powerful tool to isolate and unit test any view related business logic without involving the view itself. You'll also learn how FRP enables you to better manage change and introduce new features. The final part of this book focuses on higher-level application design concerns and strategies as you look at architectural approaches and frameworks that work well with FRP thinking.

Table of Contents detailed table of contents

Part 1: Core Reactive Programming

1. Introduction to reactive programming

1.1. Perhaps you picked up this bookbecause…​

1.2. Don't read this book if…​

1.3. OOP, Rx, FP and FRP

1.4. The Benefits of Rx

1.5. What You Code is What You Get

1.6. The Reactive Landscape

1.7. What do you need to know before we start?

1.8. About the Book

1.9. RxJava and Android

1.10. Setting up the Android Environment

1.11. Java 8 Lambdas

1.13. Project Set Up

1.14. Text input as a producer of data

1.15. The Publish-Subscribe pattern

1.16. Text input as an Observable

1.17. Filtering Observables

1.18. Bending time

1.19. Bending time in our benefit

1.20. Debounce: The Bus Stop Operator

1.21. Putting it into Android

1.22. Coffee Break

1.23. Principles of Reactive Programming

1.24. Events and Marble Diagrams

1.25. Summary

2. Networking with observables

2.1. RxJava and Event Streams

2.2. Subscribers

2.3. What Happens when We Make a Normal Network Request?

2.4. What Happens when we Make a Network Request with an Observable?

2.5. Network Request as an Observable

2.6. Example: An RSS Feed Aggregator

2.7. The feed structure

2.8. Getting the Data

2.9. The combineLatest Operator

2.10. The Rx Code so far

2.11. Coffee Break

2.12. Asynchronous Data Processing Chains

2.13. Putting the List in Order

2.14. The map Operator

2.15. Brief Introduction to Immutability

2.16. Error Handling

2.17. Adding More Feeds to the Client

2.18. Summary

3. Building data processing chains

3.1. Different Kinds of Observables

3.2. Events versus Reactive State

3.3. Internal State of an Observable

3.4. Arrow Diagrams and Different Observable Types

3.5. Example: Credit Card Validation Form

3.6. First step: Expiration Date

3.7. Credit Card Number Type and Checksum

3.8. CVC Code Validation

3.9. Putting it all Together

3.10. Coffee Break

3.11. The Abstraction level of Reactive Programming

3.12. How RxJava works

3.13. Summary

4. Connecting the user interface with networking

4.1. Subscriptions Explained

4.2. Terminating

4.3. Advanced Rx Chains Example: Flickr Search Client

4.4. Setting Up the Flickr Client Project

4.5. Overview of the Search Chain

4.7. Making it Click

4.8. Implementing the Reactive Chain

4.9. How switchMap Works

4.10. Coffee Break

4.11. Getting Thumbnail Information

4.12. Step 1: Expand the List into an Observable

4.13. Step 2: Apply Operations to each ItemIndividually

4.14. Step 3: Aggregate Results

4.15. The Complete Solution

4.16. Adding Username from Another API

4.17. Summary

5. Advanced RxJava

5.1. Observables and Subjects in Detail

5.2. Example: File Browser

5.3. User Flow of the File Browser App

5.4. Getting the File Listing for a Directory

5.5. Threading Basics

5.6. Threading in Functional Programming

5.7. Changing the Thread Using the getFileListingObservable

5.8. Making the File Listing Dynamic

5.9. Making the List Click

5.10. Different Types of Subjects

5.11. Using a Subject as the FileObservable

5.12. Coffee Break

5.13. Adding Buttons for Back and Root

5.14. Expanded Graph for Back and Root

5.15. Improved Version with Cleaner Observables

5.16. The previous Button

5.17. Putting it all Together

5.18. The Detailed Graph

5.19. The Full Code so Far

5.20. Saving and Releasing the Subscriptions

5.21. A Final Note on Subjects

5.22. Summary

Part 2: Architectures in Reactive

6. Reactive View Models

6.1. The View Layer

6.2. Platform Containers

6.3. View Models

6.4. The Blueprint of a View Model

6.5. Connecting Views and View Models

6.6. The Whole Picture

6.7. View Model Life Cycle

6.8. Coffee Break

6.9. View Models and Android Life Cycles

6.10. The View Affinity of the Code

6.11. Summary

7. Reactive Architectures

7.1. Fundamentals of Reactive Architectures

7.2. Model - View - View Model

7.3. Reactive Model

7.4. Retrieving data from the Model

7.5. Coffee Break

7.6. Revising the File Browser

7.7. Constructing the Model for the File Browser

7.8. Using the Model

7.9. Rules of the Model and its Consumers

7.10. Single Source of Truth

7.11. Coffee Break

7.12. Persisting App State

7.13. BehaviorSubjecs and Stores

7.14. Simple SharedPreferences Store

7.15. Summary

8. Developing with view models

8.1. View Models and the View

8.2. Example: Tic-Tac Toe

8.3. Drawing the Game Grid

8.4. Making it Interactive

8.5. Events Versus Reactive State

8.6. Immutable Data and the Game Grid

8.7. Adding the Code for Interaction

8.8. Coffee Break

8.9. Wrapping the Logic into a View Model

8.10. Click Coordinate Processing

8.11. Changing Turns

8.12. Coffee Break

8.13. Filtering Illegal Moves

8.14. Winning Conditions

8.15. One More Thing: Restarting the Game

8.16. Summary

9. Expanding existing Rx apps

9.1. Working with Existing Reactive Code

9.2. The Game of Connect Four

9.3. Updating Grid Size and Assets

9.4. Checking for Valid Moves

9.5. Coffee Break

9.6. Saving and Loading the Game

9.7. Creating the Model

9.8. Sharing the Model

9.9. Loaded Games Activity

9.10. PersistedGameStore

9.11. Saving Games

9.12. Summary

10. Testing Reactive Code

10.1. Reactive Architectures and Testing

10.2. Test Granularity

10.3. The Pyramid of Dependencies

10.4. Unit Testing Basics

10.5. Testing Reactive Chains

10.6. TestSubscriber Class

10.7. Synchronous or Asynchronous

10.8. Coffee Break

10.9. Writing Tests For View Models

10.10. Choosing What to Test

10.11. Testing GameViewModel Initial State

10.12. Testing Partial Observable Chains

10.13. Testing Connect Four Drop Logic

10.14. Summary

Part 3: Advanced Reactive

11. Advanced Architectures Chat Client 1

11.1. Chat Client with Web Socket

11.2. How to Transfer Messages?

11.3. Web Sockets

11.4. WebSockets as Broadcasters

11.5. Connecting to the Server

11.6. ChatMessage Structure

11.7. Sending ChatMessages

11.8. Wrapping Listeners into Observables

11.9. Coffee Break

11.10. Solution to Coffee Break

11.11. Basic UI

11.12. Showing Messages

11.13. The View Model

11.14. Accumulating ChatMessages

11.15. Putting Together Message Processing

11.16. Consuming Values from View Model

11.17. View Model Life Cycle

11.18. Making View Model Life Cycle

11.19. Summary

12. Making a Model layer

13. Animations with FRP

14. Making a maps client


Appendix A: RxJava basics

Appendix B: Android manual

What's inside

  • Learn with lots of illustrations and real-life app examples
  • Using FRP in your day-to-day programming
  • Understand a new way of seeing programs as pipelines of data
  • Tackle asynchronous programming with a sustainable approach
  • Handing increasing complexity in UIs

About the reader

Readers should have a basic understanding of mobile UI development and be familiar with traditional object-oriented programming paradigms.

About the author

Timo Tuominen has used FRP and RxJava extensively as an architect of a major Android project for Samsung while working with Futurice. As a consultant he has developed dozens of agile projects on almost all relevant platforms - and a number of dead ones - nowadays bringing FRP to wherever he can.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $44.99 pBook + PDF
MEAP eBook $35.99 PDF only

FREE domestic shipping on three or more pBooks