Code block below produces different results depending on if print is commented or not:
Without print:
With print:
Code Block import Combine var cancellables = Set<AnyCancellable>() enum FruitError: Error { case bad } var fruit = "apple" func getFruit() -> String { fruit } Just(getFruit) //.print() .map{$0()} .flatMap { value -> AnyPublisher<String, FruitError> in print("in flat map \(value)") if value == "apple" { fruit = "pineapple" return Fail(error: FruitError.bad).eraseToAnyPublisher() } return Just("banana").setFailureType(to: FruitError.self).eraseToAnyPublisher() } .retry(1) .sink(receiveCompletion: { print($0) }, receiveValue: {print($0)}) .store(in: &cancellables)
Without print:
Code Block in flat map apple in flat map apple failure
With print:
Code Block in flat map apple in flat map pineapple banana receive finished finished receive finished Why does print or any other debug operator(breakpoint or handleEvent) change behaviour of sequence?