Suppose you are given the task of writing code that fulfils the following contract:
You will be given a promise that, at some point in the future, some data – a series of values – will become available.
In return, you will supply a promise that, at some point in the future, some data representing the results of processing that data will become available.
There may be more values to process than you can fit in memory, or even an infinite series of values.
You are allowed to specify what will be done with each individual value, as and when it becomes available; this includes discarding some values.
Whenever you want to use some external service to do something with a value, that service can only return you a promise that, at some point in the future, some data representing the result of processing that value will become available.
This blog is written exclusively by the OpenCredo team. We do not accept external contributions.