Skip to content

Commit afe072f

Browse files
committed
Add playground page and README
1 parent d4684a8 commit afe072f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Playground/RxSwiftExtPlayground.playground/Pages/Index.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- [ofType()](ofType) operator, filters the elements of an observable sequence, if that is an instance of the supplied type.
4545
- [toSortedArray()](mapMany) operator, converts an Observable into another Observable that emits the whole sequence as a single array sorted using the provided closure and then terminates.
4646
- [count(predicate)](count) operator, counts the number of items emitted by an Observable. If predicate exists, then counts the number of items satisfying it.
47+
- [partition](partition) operator, partition a stream into two separate streams of elements that match, and don't match, the provided predicate.
4748
- **UIViewPropertyAnimator** [animate()](UIViewPropertyAnimator.animate) operator, returns a Completable that completes as soon as the animation ends.
4849
- **UIViewPropertyAnimator** [fractionComplete](UIViewPropertyAnimator.fractionComplete) binder, provides a reactive way to bind to `UIViewPropertyAnimator.fractionComplete`.
4950
*/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*:
2+
> # IMPORTANT: To use `RxSwiftExtPlayground.playground`, please:
3+
4+
1. Make sure you have [Carthage](https://github.com/Carthage/Carthage) installed
5+
1. Fetch Carthage dependencies from shell: `carthage bootstrap --platform ios`
6+
1. Build scheme `RxSwiftExtPlayground` scheme for a simulator target
7+
1. Choose `View > Show Debug Area`
8+
*/
9+
10+
//: [Previous](@previous)
11+
12+
import RxSwift
13+
import RxSwiftExt
14+
15+
example("partition") {
16+
let numbers = Observable
17+
.of(1, 2, 3, 5, 8, 13, 18, 21, 23)
18+
19+
let (evens, odds) = numbers.partition { $0 % 2 == 0 }
20+
21+
_ = evens.debug("even").subscribe()
22+
_ = odds.debug("odds").subscribe()
23+
}
24+
//: [Next](@next)
25+

Readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ These operators are much like the RxSwift & RxCocoa core operators, but provide
8181
* [Observable.zip(with:)](#zipwith)
8282
* [withUnretained](#withunretained)
8383
* [count](#count)
84+
* [partition](#partition)
8485

8586
There are two more available operators for `materialize()`'d sequences:
8687

@@ -598,6 +599,20 @@ next(3)
598599
completed
599600
```
600601

602+
#### partition
603+
604+
Partition a stream into two separate streams of elements that match, and don't match, the provided predicate.
605+
606+
```swift
607+
let numbers = Observable
608+
.of(1, 2, 3, 4, 5, 6)
609+
610+
let (evens, odds) = numbers.partition { $0 % 2 == 0 }
611+
612+
_ = evens.debug("even").subscribe() // emits 2, 4, 6
613+
_ = odds.debug("odds").subscribe() // emits 1, 3, 5
614+
```
615+
601616
Reactive Extensions details
602617
===========
603618

0 commit comments

Comments
 (0)