Skip to content

Commit 1826a29

Browse files
author
jdisho
committed
Add docs about withLatestFrom in the README
1 parent 04bcc5b commit 1826a29

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

README.md

+76-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ github "CombineCommunity/CombineExt"
7474

7575
This section outlines some of the custom operators CombineExt provides.
7676

77-
### withLatestFrom
77+
## withLatestFrom
7878

79-
Merges two publishers into a single publisher by combining each value from `self` with the _latest_ value from the second publisher, if any.
79+
### withLatestFrom(_:)
80+
81+
Merges **two** publishers into a single publisher by combining each value from `self` with the _latest_ value from the second publisher, if any.
8082

8183
```swift
8284
let taps = PassthroughSubject<Void, Never>()
@@ -100,6 +102,78 @@ withLatestFrom: Hello
100102
withLatestFrom: World!
101103
```
102104

105+
------
106+
107+
### withLatestFrom(_: _:)
108+
109+
Merges **three** publishers into a single publisher by combining each value from `self` with the *latest* value from the second and third publisher, if any.
110+
111+
```swift
112+
let taps = PassthroughSubject<Void, Never>()
113+
let strings = CurrentValueSubject<String, Never>("Hello")
114+
let ints = CurrentValueSubject<Int, Never>(0)
115+
116+
taps
117+
.withLatestFrom(strings, ints)
118+
.sink(receiveValue: { print("withLatestFrom: \($0.0),\($0.1)") })
119+
120+
taps.send()
121+
taps.send()
122+
strings.send("World!")
123+
taps.send()
124+
ints.send(1)
125+
ints.send(2)
126+
taps.send()
127+
```
128+
129+
#### Output
130+
131+
```none
132+
withLatestFrom: Hello,0
133+
withLatestFrom: Hello,0
134+
withLatestFrom: World!,0
135+
withLatestFrom: World!,2
136+
```
137+
138+
------
139+
140+
### withLatestFrom(_: _: _:)
141+
142+
Merges **four** publishers into a single publisher by combining each value from `self` with the *latest* value from the second, third and fourth publisher, if any.
143+
144+
```swift
145+
let taps = PassthroughSubject<Void, Never>()
146+
let strings = CurrentValueSubject<String, Never>("Hello")
147+
let ints = CurrentValueSubject<Int, Never>(0)
148+
let bools = CurrentValueSubject<Int, Never>(true)
149+
150+
taps
151+
.withLatestFrom(strings, ints)
152+
.sink(receiveValue: { print("withLatestFrom: \($0.0),\($0.1),\($0.2)") })
153+
154+
taps.send()
155+
taps.send()
156+
strings.send("World!")
157+
bools.send(true)
158+
taps.send()
159+
ints.send(1)
160+
bools.send(true)
161+
bools.send(false)
162+
ints.send(2)
163+
taps.send()
164+
```
165+
166+
#### Output
167+
168+
```none
169+
withLatestFrom: Hello,0,true
170+
withLatestFrom: Hello,0,true
171+
withLatestFrom: World!,0,true
172+
withLatestFrom: World!,2,false
173+
```
174+
175+
176+
103177
------
104178

105179
### flatMapLatest

0 commit comments

Comments
 (0)