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
| let strings1 = PassthroughSubject<String, Never>() | |
| let strings2 = PassthroughSubject<String, Never>() | |
| strings1 | |
| .merge(with: strings2) | |
| .sink { print($0) } | |
| strings2.send("A") | |
| strings1.send("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
| let intPublisher1 = PassthroughSubject<Int, Never>() | |
| let intPublisher2 = PassthroughSubject<Int, Never>() | |
| let publishers = PassthroughSubject<PassthroughSubject<Int, Never>, Never>() | |
| publishers.switchToLatest().sink { print($0) } | |
| publishers.send(intPublisher1) | |
| intPublisher1.send(-3) |
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
| let integers = (10...12).publisher // A | |
| let moreIntegers = (20...22).publisher // F | |
| integers | |
| .append(1, 2) // B | |
| .append(99...101) // C | |
| .append([-100, -200]) // D | |
| .append(moreIntegers) // E | |
| .sink { print($0) } |
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
| let integers = (10...12).publisher // F | |
| let moreIntegers = (20...22).publisher // A | |
| integers | |
| .prepend(1, 2) // B | |
| .prepend(99...101) // C | |
| .prepend([-100, -200]) // D | |
| .prepend(moreIntegers) // E | |
| .sink { print($0) } |
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
| let on = PassthroughSubject<Void, Never>() | |
| let strings = PassthroughSubject<String, Never>() | |
| strings | |
| .prefix(untilOutputFrom: on) | |
| .sink(receiveValue: { print($0) }) | |
| ["a1", "b1", "c3", "d1", "e5"] | |
| .forEach { | |
| strings.send($0) |
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
| let strings = PassthroughSubject<String, Never>() | |
| strings | |
| .prefix(while: { $0.hasSuffix("1") }) | |
| .sink(receiveValue: { print($0) }) | |
| ["a1", "b1", "c3", "d1", "e5"] | |
| .forEach { | |
| strings.send($0) | |
| } |
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
| let strings = PassthroughSubject<String, Never>() | |
| strings | |
| .prefix(3) | |
| .sink(receiveValue: { print($0) }) | |
| ["a", "b", "c", "d", "e"] | |
| .forEach { | |
| strings.send($0) | |
| } |
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
| let on = PassthroughSubject<Void, Never>() | |
| let strings = PassthroughSubject<String, Never>() | |
| strings | |
| .drop(untilOutputFrom: on) | |
| .sink(receiveValue: { print($0) }) | |
| ["a0", "a1", "b2", "a3", "c4", "a5", "d6"] | |
| .forEach { | |
| strings.send($0) |
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 | |
| ["a0", "a1", "b2", "a3", "c4", "a5", "d6"] | |
| .publisher | |
| .drop(while: { $0.hasPrefix("a") }) | |
| .sink { print($0) } | |
| // Output: | |
| // b2 | |
| // a3 |
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
| [1, 2, 3] | |
| .publisher | |
| .dropFirst() | |
| .sink { print($0) } | |
| // Output: | |
| // 2 | |
| // 3 |
NewerOlder