You've seen how to chain sequence operations together. By doing this, you can pass one value at a time to your chain and into your side-effect. This lets you write legible code that doesn't create intermediary collections between operations. However, you can still run into performance problems with large collections because you'll still have to iterate over every value.
Use the take()
method to tell sequences that you only want a specific number of results. For example, if a page in your application wants to display 20 values, you could add take(20)
to your sequence chain. Where should you add this call? The order of where take()
is placed in the chain of method calls can have dramatic effects on the result.
Let's start by creating an infinite sequence, as shown in the following code block:
import { Range } from 'immutable'; const myRange = Range();
Here, Range
is a special type of sequence that's handy for creating large sequences...