
Hands-On Reactive Programming with Clojure
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Learn how to use RxClojure to deal with stateful computations
Key Features
- Leverage the features of Functional Reactive Programming using Clojure
- Create dataflow-based systems that are the building blocks of Reactive Programming
- Use different Functional Reactive Programming frameworks, techniques, and patterns to solve real-world problems
Book Description
Reactive Programming is central to many concurrent systems, and can help make the process of developing highly concurrent, event-driven, and asynchronous applications simpler and less error-prone.
This book will allow you to explore Reactive Programming in Clojure 1.9 and help you get to grips with some of its new features such as transducers, reader conditionals, additional string functions, direct linking, and socket servers. Hands-On Reactive Programming with Clojure starts by introducing you to Functional Reactive Programming (FRP) and its formulations, as well as showing you how it inspired Compositional Event Systems (CES). It then guides you in understanding Reactive Programming as well as learning how to develop your ability to work with time-varying values thanks to examples of reactive applications implemented in different frameworks. You'll also gain insight into some interesting Reactive design patterns such as the simple component, circuit breaker, request-response, and multiple-master replication. Finally, the book introduces microservices-based architecture in Clojure and closes with examples of unit testing frameworks.
By the end of the book, you will have gained all the knowledge you need to create applications using different Reactive Programming approaches.
What you will learn
- Understand how to think in terms of time-varying values and event streams
- Create, compose, and transform observable sequences using Reactive extensions
- Build a CES framework from scratch using core.async as its foundation
- Develop a simple ClojureScript game using Reagi
- Integrate Om and RxJS in a web application
- Implement a reactive API in Amazon Web Services (AWS)
- Discover helpful approaches to backpressure and error handling
- Get to grips with futures and their applications
Who this book is for
If you're interested in using Reactive Programming to build asynchronous and concurrent applications, this is the book for you. Basic knowledge of Clojure programming is necessary to understand the concepts covered in this book.
More details
Other editions
Additional editions

Content
- Cover
- Title Page
- Copyright and Credits
- About Packt
- Contributors
- Table of Contents
- Preface
- Chapter 1: What is Reactive Programming?
- A taste of Reactive Programming
- The concept of time in RxJS
- More colors
- Making it reactive
- Exercise 1.1
- A bit of history
- Dataflow programming
- Object-oriented Reactive Programming
- The most widely used reactive program
- The Observer design pattern
- Functional Reactive Programming
- Higher-order FRP
- Signals and events
- Implementation challenges
- First-order FRP
- Asynchronous data flow
- Arrowized FRP
- Applications of FRP
- Asynchronous programming and networking
- Complex GUIs and animations
- Summary
- Further reading
- Chapter 2: A Look at Reactive Extensions
- The observer pattern revisited
- Observer - an iterator's dual
- Creating observables
- Custom observables
- Manipulating observables
- flatmap and friends
- One more flatmap for the road
- Error handling
- OnError
- Catch
- Retry
- Backpressure
- Sample
- Backpressure strategies
- Summary
- Further reading
- Chapter 3: Asynchronous Programming and Networking
- Building a stock market monitoring application
- Rolling averages
- Identifying problems with our current approach
- Removing incidental complexity with RxClojure
- Observable rolling averages
- Summary
- Chapter 4: Introduction to core.async
- Asynchronous programming and concurrency
- The core.async library
- The Communicating Sequential Processes paper
- Rewriting the stock market application with core.async
- Implementing the application code
- Error handling
- Backpressure
- Fixed buffer
- Dropping buffer
- Sliding buffer
- Transducers
- Transducers and core.async
- Summary
- Further reading
- Chapter 5: Creating Your Own CES Framework with core.async
- A minimal CES framework
- Clojure or ClojureScript?
- Designing the public API
- Implementing tokens
- Implementing event streams
- Implementing behaviors
- Exercises
- Exercise 5.1
- Exercise 5.2
- A respondent application
- CES versus core.async
- Summary
- Further reading
- Chapter 6: Building a Simple ClojureScript Game with Reagi
- Setting up the project
- Game entities
- Putting it all together
- Modeling user input as event streams
- Working with the active keys stream
- Reagi and other CES frameworks
- Summary
- Further reading
- Chapter 7: The UI as a Function
- The problem with complex web UIs
- Enter React.js
- Lessons from functional programming
- ClojureScript and Om
- Building a simple Contacts application with Om
- Setting up the Contacts project
- Application components
- Managing application state
- Om components
- Query expressions
- Filling in the blanks
- Identity
- Intercomponent communication
- Creating an agile board with Om
- The board state
- Components overview
- Life cycle and component local state
- Remaining components
- Utility functions
- Application's parser
- Exercises
- Summary
- Further reading
- Chapter 8: A New Approach to Futures
- Clojure futures
- Fetching data in parallel
- Imminent - a composable futures library for Clojure
- Creating futures
- Combinators and event handlers
- The movies example revisited
- Futures and blocking IO
- Summary
- Further reading
- Chapter 9: A Reactive API to Amazon Web Services
- Amazon Services use case
- Infrastructure automation
- AWS resources dashboard
- CloudFormation
- The describeStacks endpoint
- The describeStackResources endpoint
- Elastic Compute Cloud Service
- The describeInstances endpoint
- Relational Database Service
- The describeDBInstances endpoint
- Designing the solution
- Running the AWS stub server
- Setting up the dashboard project
- Creating AWS Observables
- Combining the AWS Observables
- Putting it all together
- Exercises
- Summary
- Further reading
- Chapter 10: Reactive Microservices
- An introduction to microservices
- Advantages of microservices
- Scalability
- Disadvantages of microservices
- When to use microservices
- Microservices best practices
- Domain Driven Design
- Separate data storage
- Team building and structure
- Deployment
- Failure isolation
- Cross-cutting concerns
- Communication between services
- Event-driven communication
- The CQRS communication pattern
- Common pitfalls
- Attitudes towards microservices
- Service boundaries
- Service granularity
- Service separation
- Build dependencies
- Services contracts
- Services communication
- DevOps
- RESTful microservices in action
- Application overview
- Services messaging
- A Clojure RESTful service
- Setting up the project structure
- Database operations with Toucan
- Coercion with the schema
- The Card API
- Compojure HTTP API
- The GET Card API
- The GET Cards API
- The UPDATE Card API
- The DELETE Card API
- The Swagger UI
- Summary
- Further reading
- Chapter 11: Testing Reactive Apps
- Why testing is important
- Testing approaches
- Functional testing
- Non-functional testing
- Clojure unit testing frameworks
- The clojure.test framework
- The is macro
- The are macro
- The expectations framework
- The Midje framework
- The fact macro
- The facts macro
- Top-down testing
- Checking for exceptions
- Checking collections
- The contains macro
- The just macro
- The Speclj framework
- The should-contain macro
- The should= and should== macros
- The should-throw macro
- The should-be-a macro
- Summary
- Further reading
- Chapter 12: Concurrency Utilities in Clojure
- Introduction to concurrency
- Concurrency or parallelism
- State, identity, and value
- Common problems with states
- Lost updates
- Unrepeatable reads
- Phantom reads
- The traditional solution to the problem with states
- Deadlock
- Starvation
- Livelock
- Race conditions
- Other problems with locks
- The Clojure approach to concurrency
- Classifying constructs
- Synchronization
- Coordination
- Atoms
- Dereferencing atoms
- Mutating atoms
- reset!
- swap!
- compare-and-set!
- Agents
- Dereferencing agents
- Mutating agents
- send
- send-off
- Refs
- Dereferencing refs
- Mutating refs
- Software Transactional Memory
- ref-set
- alter
- commute
- Vars
- Var bindings
- Private vars
- Constant vars
- Futures and promises in Clojure
- Futures
- Promises
- Summary
- Further reading
- Appendix - The Algebra of Library Design
- Other Books You May Enjoy
- Index
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.