Implementing state with scan in RxSwift

Intro Common misconception is that you cannot have state with Rx. Well you can - and there’s a special operator that helps you to: scan. If you’ve ever used reduce in Swift - scan is a very similar operator but reduce goes over the complete sequence and gives you the final value of the accumulator while scan emits each intermediate value as well. If you haven’t used reduce - no worries you’ll get to understand scan from the examples below.