You are previewing Clojure Reactive Programming.
O'Reilly logo
Clojure Reactive Programming

Book Description

Design and implement highly reusable reactive applications by integrating different frameworks with Clojure

In Detail

Reactive Programming (RP) is central to many concurrent systems. It endeavors to make the process of developing highly-concurrent, event-driven, and asynchronous applications simpler and less error-prone. RP comes in many flavors and we will look at some of them in this book.

Clojure Reactive Programming is a practical guide aimed at exploring RP. It starts by describing Functional Reactive Programming (FRP) and its formulations, as well as how it inspired Compositional Event Systems (CES).

It also presents several examples of Reactive applications implemented in different frameworks, allowing you to develop an understanding of the subject as well as learn how to develop your ability to work with time-varying values.

By the end of the book, you will be equipped to solve real-world problems as well as understand the trade-offs between the approaches shown in the book.

What You Will Learn

  • Understand the key abstractions of Functional Reactive Programming (FRP) and Compositional Event Systems (CES)

  • Discover how to think in terms of time-varying values and event streams

  • Create, compose, and transform Observable sequences with Reactive Extensions

  • Create a CES framework from scratch using core.async as its foundation

  • Build a simple ClojureScript game using Reagi

  • Integrate Om and RxJS in a web application

  • Implement a reactive API to Amazon Web Services

  • Discover approaches to backpressure and error handling

  • Get to grips with futures and learn where they fit in

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Clojure Reactive Programming
      1. Table of Contents
      2. Clojure Reactive Programming
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. What is Reactive Programming?
        1. A taste of Reactive Programming
          1. Creating time
          2. More colors
          3. Making it reactive
          4. Exercise 1.1
        2. A bit of history
          1. Dataflow programming
          2. Object-oriented Reactive Programming
          3. The most widely used reactive program
          4. The Observer design pattern
          5. Functional Reactive Programming
          6. Higher-order FRP
        3. Signals and events
        4. Implementation challenges
          1. First-order FRP
          2. Asynchronous data flow
          3. Arrowized FRP
        5. Applications of FRP
          1. Asynchronous programming and networking
          2. Complex GUIs and animations
        6. Summary
      10. 2. A Look at Reactive Extensions
        1. The Observer pattern revisited
          1. Observer – an Iterator's dual
        2. Creating Observables
          1. Custom Observables
        3. Manipulating Observables
        4. Flatmap and friends
          1. One more flatmap for the road
        5. Error handling
          1. OnError
          2. Catch
          3. Retry
        6. Backpressure
          1. Sample
          2. Backpressure strategies
        7. Summary
      11. 3. Asynchronous Programming and Networking
        1. Building a stock market monitoring application
        2. Rolling averages
        3. Identifying problems with our current approach
        4. Removing incidental complexity with RxClojure
          1. Observable rolling averages
        5. Summary
      12. 4. Introduction to core.async
        1. Asynchronous programming and concurrency
        2. core.async
          1. Communicating sequential processes
        3. Rewriting the stock market application with core.async
          1. Implementing the application code
        4. Error handling
        5. Backpressure
          1. Fixed buffer
          2. Dropping buffer
          3. Sliding buffer
        6. Transducers
          1. Transducers and core.async
        7. Summary
      13. 5. Creating Your Own CES Framework with core.async
        1. A minimal CES framework
          1. Clojure or ClojureScript?
          2. Designing the public API
          3. Implementing tokens
          4. Implementing event streams
          5. Implementing behaviors
        2. Exercises
          1. Exercise 5.1
          2. Exercise 5.2
        3. A respondent application
        4. CES versus core.async
        5. Summary
      14. 6. Building a Simple ClojureScript Game with Reagi
        1. Setting up the project
          1. Game entities
          2. Putting it all together
          3. Modeling user input as event streams
          4. Working with the active keys stream
        2. Reagi and other CES frameworks
        3. Summary
      15. 7. The UI as a Function
        1. The problem with complex web UIs
        2. Enter React.js
          1. Lessons from functional programming
        3. ClojureScript and Om
        4. Building a simple Contacts application with Om
          1. The Contacts application state
          2. Setting up the Contacts project
          3. Application components
          4. Om cursors
          5. Filling in the blanks
        5. Intercomponent communication
          1. Creating an agile board with Om
          2. The board state
          3. Components overview
          4. Lifecycle and component local state
          5. Remaining components
          6. Utility functions
        6. Exercises
        7. Summary
      16. 8. Futures
        1. Clojure futures
        2. Fetching data in parallel
        3. Imminent – a composable futures library for Clojure
          1. Creating futures
          2. Combinators and event handlers
        4. The movies example revisited
        5. Futures and blocking IO
        6. Summary
      17. 9. A Reactive API to Amazon Web Services
        1. The problem
        2. Infrastructure automation
        3. AWS resources dashboard
        4. CloudFormation
          1. The describeStacks endpoint
          2. The describeStackResources endpoint
        5. EC2
          1. The describeInstances endpoint
        6. RDS
          1. The describeDBInstances endpoint
        7. Designing the solution
          1. Running the AWS stub server
          2. Setting up the dashboard project
          3. Creating AWS Observables
          4. Combining the AWS Observables
          5. Putting it all together
        8. Exercises
        9. Summary
      18. A. The Algebra of Library Design
        1. The semantics of map
          1. Functors
          2. The Option Functor
        2. Finding the average of ages
        3. Applicative Functors
        4. Gathering stats about ages
        5. Monads
        6. Summary
      19. B. Bibliography
      20. Index