9 Streams programming

 

This chapter covers

  • Reviewing the Iterator/Iterable protocols
  • Using generators to represent iterable sequences of values over time
  • Reviewing the push/pull models as well as stream-based programming
  • Using observables to create declarative, asynchronous push streams

An Observable is a function that takes an observer and returns a function. Nothing more, nothing less. If you write a function that takes an observer and returns a function, is it async or sync? Neither. It’s a function.

—Ben Lesh

9.1 Iterables and Iterators

9.1.1 Iterable protocol

9.1.2 Iterator protocol

9.1.3 Examples

9.2 Generators

9.2.1 To return or to yield

9.2.2 Creating iterable objects

9.2.3 Async generators

9.3 Working with data streams

9.3.1 What is a stream?

9.3.2 Implementing a streamable array

9.4 Welcoming a new native: Observable

9.4.1 What is an Observable?

9.4.2 Creating custom observables

9.4.3 Building your own reactive toolkit

9.4.4 Observable mixin extension

9.4.5 Representing push streams with generators

9.4.6 Pipeable operators