Home > AI > IOS > Combine >

scan(_:_:)

Example (Apple Official)

let range = (0...5)
let cancellable = range.publisher
    .scan(2) { return $0 + $1 }
    .sink { print ("\($0)", terminator: " ") }

// 2 3 5 8 12 17 

// original 0, 1, 2, 3, 4, 5
// scan 2, 3, 5, 8, 12, 17

Leave a Reply