This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
func stringIfOver42(_ value: Int) -> String? { | |
value > 42 ? "\(value)" : nil | |
} | |
let voidSubject = PassthroughSubject<Void, Never>() | |
let intSubject = PassthroughSubject<Int, Never>() | |
let publisher = voidSubject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import Foundation | |
let c = Publishers | |
.CombineLatest( | |
Just(true) | |
.delay(for: .seconds(0.5), scheduler: DispatchQueue(label: "A")) | |
.prepend(false), | |
Just(true) | |
.delay(for: .seconds(1), scheduler: DispatchQueue(label: "B")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testCombineLatest() { | |
for _ in 1...100 { | |
let e = expectation(description: "Each subject should emit true") | |
let s1 = CurrentValueSubject<Bool, Never>(false) | |
let s2 = CurrentValueSubject<Bool, Never>(false) | |
let cancellable = Publishers.CombineLatest(s1, s2) | |
.sink { | |
if $0, $1 { | |
e.fulfill() | |
} |