Skip to content

Commit

Permalink
Add docs about withLatestFrom in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisho committed Apr 19, 2020
1 parent 04bcc5b commit 1826a29
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ github "CombineCommunity/CombineExt"

This section outlines some of the custom operators CombineExt provides.

### withLatestFrom
## withLatestFrom

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

Merges **two** publishers into a single publisher by combining each value from `self` with the _latest_ value from the second publisher, if any.

```swift
let taps = PassthroughSubject<Void, Never>()
Expand All @@ -100,6 +102,78 @@ withLatestFrom: Hello
withLatestFrom: World!
```

------

### withLatestFrom(_: _:)

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.

```swift
let taps = PassthroughSubject<Void, Never>()
let strings = CurrentValueSubject<String, Never>("Hello")
let ints = CurrentValueSubject<Int, Never>(0)

taps
.withLatestFrom(strings, ints)
.sink(receiveValue: { print("withLatestFrom: \($0.0),\($0.1)") })

taps.send()
taps.send()
strings.send("World!")
taps.send()
ints.send(1)
ints.send(2)
taps.send()
```

#### Output

```none
withLatestFrom: Hello,0
withLatestFrom: Hello,0
withLatestFrom: World!,0
withLatestFrom: World!,2
```

------

### withLatestFrom(_: _: _:)

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.

```swift
let taps = PassthroughSubject<Void, Never>()
let strings = CurrentValueSubject<String, Never>("Hello")
let ints = CurrentValueSubject<Int, Never>(0)
let bools = CurrentValueSubject<Int, Never>(true)

taps
.withLatestFrom(strings, ints)
.sink(receiveValue: { print("withLatestFrom: \($0.0),\($0.1),\($0.2)") })

taps.send()
taps.send()
strings.send("World!")
bools.send(true)
taps.send()
ints.send(1)
bools.send(true)
bools.send(false)
ints.send(2)
taps.send()
```

#### Output

```none
withLatestFrom: Hello,0,true
withLatestFrom: Hello,0,true
withLatestFrom: World!,0,true
withLatestFrom: World!,2,false
```



------

### flatMapLatest
Expand Down

0 comments on commit 1826a29

Please sign in to comment.