Step into Swift logo

What is the Scan Operator in RxSwift?

Scan Operator

RxSwift: Scan Operator

.scan { }

  • Applies a supplied predicate to the elements emitted by an Observable, sequentially, emitting each successful result.
  • Applies function to first element and then uses the result of this as the parameter for the second emitted elements applied function, and so on.
  • Acts like an accumulator.
  • Useful for for running totals, statistics, states…
--1--2--3--4--------5-------->

scan((x, y) => x * y)

--1--2--6--24-------120------>

< All Posts