Search⌘ K

Flattening

Explore techniques for flattening arrays, promises, and observables in RxJS. Understand how flatMap and mergeMap operators help combine and control data streams for efficient reactive programming.

Flattening streams

Flattening arrays

You may have heard of a flatten function.

flatten functions take an input of some sort and “unwrap” it. (In this case, unwrapping an array is to pull out the elements in the array and use those.)

This hypothetical code snippet returns [2, 4, 7, 12]:

flatten([[2], [4, 7], 12])

Usually, a single call to flatten only unwraps by one layer.

Flattening promises and observables

Flatten iterates through the array, unwrapping ...