Chapter 3

What is a pure function?

A pure function is a function whose output depends only on its input parameters. A pure function has a deterministic behavior. This means that if it is called several times with the same values as input, then it will returns the same results. This deterministic behavior is called referential transparency in functional programming.

What is a higher-order function?

A higher-order function is a function that takes a function as an input parameter, and/or returns a function as an output. Higher-order functions are very useful for implementing abstractions or generic behaviors.

Why should side-effects be as small as possible?

Side-effects are parts of code that are not deterministic. This implies that this code is more difficult to test than pure code. So, making the footprint of side-effects as small as possible makes the whole application easier to test.

What is an observable cycle?

An observable cycle is the fact that several observables are inter-dependent. When an observable cycle is present, at some point an observable needs a reference to an observable that may not be yet available. This is a very common situation. An easy way to deal with it is to use subjects.

How can you wait in a coroutine until a item is received on an observable?

Coroutines can only wait for coroutines or futures to complete, via the await keyword. So, the easiest way to resume a coroutine when an item is emitted on a stream is to make this item emission complete a future. This is done by calling the set_result method of a future in the on_next callback of the observer.

How can you combine two observables into a single one?

There are several operators that allow us to combine several observables. One of the most commonly used ones is the merge operator. The merge operator combines several observables and returns an observable that contains all the items emitted by its source observables.

Would you implement some code that writes pixels to a screen as a component or as a driver? Why?

Writing pixels on a screen is an I/O operation (and, more specifically, a write operation). Any code that handles I/O operations should be written as a driver because it is a side-effect. Side-effects must be implemented as drivers. Components only contain pure code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.75.221