Skip to content

Commit 3f5f9cc

Browse files
committed
Adds deprecated warnings to API parts that were missing it. ReactiveX#1427
1 parent 79489cf commit 3f5f9cc

9 files changed

+13
-1193
lines changed

RxSwift/Deprecated.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ extension Observable {
3838
extension ObservableType {
3939
/**
4040

41-
** @available(*, deprecated, message: "Please use enumerated().map()", renamed: "enumerated().map()") **
42-
43-
Projects each element of an observable sequence into a new form by incorporating the element's index.
41+
Projects each element of an observable sequence into a new form by incorporating the element's index.
4442

4543
- seealso: [map operator on reactivex.io](http://reactivex.io/documentation/operators/map.html)
4644

4745
- parameter selector: A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
4846
- returns: An observable sequence whose elements are the result of invoking the transform function on each element of source.
4947
*/
48+
@available(*, deprecated, message: "Please use enumerated().map()")
5049
public func mapWithIndex<R>(_ selector: @escaping (E, Int) throws -> R)
5150
-> Observable<R> {
5251
return enumerated().map { try selector($0.element, $0.index) }
@@ -55,24 +54,21 @@ extension ObservableType {
5554

5655
/**
5756

58-
** @available(*, deprecated, message: "Please use enumerated().flatMap()", renamed: "enumerated().flatMap()") **
59-
6057
Projects each element of an observable sequence to an observable sequence by incorporating the element's index and merges the resulting observable sequences into one observable sequence.
6158

6259
- seealso: [flatMap operator on reactivex.io](http://reactivex.io/documentation/operators/flatmap.html)
6360

6461
- parameter selector: A transform function to apply to each element; the second parameter of the function represents the index of the source element.
6562
- returns: An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.
6663
*/
64+
@available(*, deprecated, message: "Please use enumerated().flatMap()")
6765
public func flatMapWithIndex<O: ObservableConvertibleType>(_ selector: @escaping (E, Int) throws -> O)
6866
-> Observable<O.E> {
6967
return enumerated().flatMap { try selector($0.element, $0.index) }
7068
}
7169

7270
/**
7371

74-
** @available(*, deprecated, message: "Please use enumerated().skipWhile().map()", renamed: "enumerated().skipWhile().map()") **
75-
7672
Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
7773
The element's index is used in the logic of the predicate function.
7874

@@ -81,15 +77,14 @@ extension ObservableType {
8177
- parameter predicate: A function to test each element for a condition; the second parameter of the function represents the index of the source element.
8278
- returns: An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
8379
*/
80+
@available(*, deprecated, message: "Please use enumerated().skipWhile().map()")
8481
public func skipWhileWithIndex(_ predicate: @escaping (E, Int) throws -> Bool) -> Observable<E> {
8582
return enumerated().skipWhile { try predicate($0.element, $0.index) }.map { $0.element }
8683
}
8784

8885

8986
/**
90-
91-
** @available(*, deprecated, message: "Please use enumerated().takeWhile().map()", renamed: "enumerated().takeWhile().map()") **
92-
87+
9388
Returns elements from an observable sequence as long as a specified condition is true.
9489

9590
The element's index is used in the logic of the predicate function.
@@ -99,6 +94,7 @@ extension ObservableType {
9994
- parameter predicate: A function to test each element for a condition; the second parameter of the function represents the index of the source element.
10095
- returns: An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
10196
*/
97+
@available(*, deprecated, message: "Please use enumerated().takeWhile().map()")
10298
public func takeWhileWithIndex(_ predicate: @escaping (E, Int) throws -> Bool) -> Observable<E> {
10399
return enumerated().takeWhile { try predicate($0.element, $0.index) }.map { $0.element }
104100
}
@@ -107,11 +103,11 @@ extension ObservableType {
107103
extension Disposable {
108104
/// Deprecated in favor of `disposed(by:)`
109105
///
110-
/// **@available(\*, deprecated, message="use disposed(by:) instead")**
111106
///
112107
/// Adds `self` to `bag`.
113108
///
114109
/// - parameter bag: `DisposeBag` to add `self` to.
110+
@available(*, deprecated, message: "use disposed(by:) instead", renamed: "disposed(by:)")
115111
public func addDisposableTo(_ bag: DisposeBag) {
116112
disposed(by: bag)
117113
}

Sources/AllTestz/main.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ final class ObservableSkipWhileTest_ : ObservableSkipWhileTest, RxTestCase {
243243
("testSkipWhile_Dispose_After", ObservableSkipWhileTest.testSkipWhile_Dispose_After),
244244
("testSkipWhile_Zero", ObservableSkipWhileTest.testSkipWhile_Zero),
245245
("testSkipWhile_Throw", ObservableSkipWhileTest.testSkipWhile_Throw),
246-
("testSkipWhile_Index", ObservableSkipWhileTest.testSkipWhile_Index),
247-
("testSkipWhile_Index_Throw", ObservableSkipWhileTest.testSkipWhile_Index_Throw),
248-
("testSkipWhile_Index_SelectorThrows", ObservableSkipWhileTest.testSkipWhile_Index_SelectorThrows),
249246
] }
250247
}
251248

@@ -556,14 +553,6 @@ final class ObservableMapTest_ : ObservableMapTest, RxTestCase {
556553
("testMap_Error", ObservableMapTest.testMap_Error),
557554
("testMap_Dispose", ObservableMapTest.testMap_Dispose),
558555
("testMap_SelectorThrows", ObservableMapTest.testMap_SelectorThrows),
559-
("testMap1_Never", ObservableMapTest.testMap1_Never),
560-
("testMap1_Empty", ObservableMapTest.testMap1_Empty),
561-
("testMap1_Range", ObservableMapTest.testMap1_Range),
562-
("testMap1_Error", ObservableMapTest.testMap1_Error),
563-
("testMap1_Dispose", ObservableMapTest.testMap1_Dispose),
564-
("testMap1_SelectorThrows", ObservableMapTest.testMap1_SelectorThrows),
565-
("testMap_DisposeOnCompleted", ObservableMapTest.testMap_DisposeOnCompleted),
566-
("testMap1_DisposeOnCompleted", ObservableMapTest.testMap1_DisposeOnCompleted),
567556
("testMapCompose_Never", ObservableMapTest.testMapCompose_Never),
568557
("testMapCompose_Empty", ObservableMapTest.testMapCompose_Empty),
569558
("testMapCompose_Range", ObservableMapTest.testMapCompose_Range),
@@ -1037,10 +1026,6 @@ final class ObservableTakeWhileTest_ : ObservableTakeWhileTest, RxTestCase {
10371026
("testTakeWhile_Dispose_After", ObservableTakeWhileTest.testTakeWhile_Dispose_After),
10381027
("testTakeWhile_Zero", ObservableTakeWhileTest.testTakeWhile_Zero),
10391028
("testTakeWhile_Throw", ObservableTakeWhileTest.testTakeWhile_Throw),
1040-
("testTakeWhile_Index1", ObservableTakeWhileTest.testTakeWhile_Index1),
1041-
("testTakeWhile_Index2", ObservableTakeWhileTest.testTakeWhile_Index2),
1042-
("testTakeWhile_Index_Error", ObservableTakeWhileTest.testTakeWhile_Index_Error),
1043-
("testTakeWhile_Index_SelectorThrows", ObservableTakeWhileTest.testTakeWhile_Index_SelectorThrows),
10441029
] }
10451030
}
10461031

@@ -1869,15 +1854,6 @@ final class ObservableMergeTest_ : ObservableMergeTest, RxTestCase {
18691854
("testFlatMap_Dispose", ObservableMergeTest.testFlatMap_Dispose),
18701855
("testFlatMap_SelectorThrows", ObservableMergeTest.testFlatMap_SelectorThrows),
18711856
("testFlatMap_UseFunction", ObservableMergeTest.testFlatMap_UseFunction),
1872-
("testFlatMapIndex_Index", ObservableMergeTest.testFlatMapIndex_Index),
1873-
("testFlatMapWithIndex_Complete", ObservableMergeTest.testFlatMapWithIndex_Complete),
1874-
("testFlatMapWithIndex_Complete_InnerNotComplete", ObservableMergeTest.testFlatMapWithIndex_Complete_InnerNotComplete),
1875-
("testFlatMapWithIndex_Complete_OuterNotComplete", ObservableMergeTest.testFlatMapWithIndex_Complete_OuterNotComplete),
1876-
("testFlatMapWithIndex_Complete_ErrorOuter", ObservableMergeTest.testFlatMapWithIndex_Complete_ErrorOuter),
1877-
("testFlatMapWithIndex_Error_Inner", ObservableMergeTest.testFlatMapWithIndex_Error_Inner),
1878-
("testFlatMapWithIndex_Dispose", ObservableMergeTest.testFlatMapWithIndex_Dispose),
1879-
("testFlatMapWithIndex_SelectorThrows", ObservableMergeTest.testFlatMapWithIndex_SelectorThrows),
1880-
("testFlatMapWithIndex_UseFunction", ObservableMergeTest.testFlatMapWithIndex_UseFunction),
18811857
("testConcatMap_InnerCompleteFasterThanOuterElementsAreProduced", ObservableMergeTest.testConcatMap_InnerCompleteFasterThanOuterElementsAreProduced),
18821858
("testConcatMap_Disposed", ObservableMergeTest.testConcatMap_Disposed),
18831859
("testConcatMap_OuterComplete_InnerNotComplete", ObservableMergeTest.testConcatMap_OuterComplete_InnerNotComplete),

Tests/RxSwiftTests/Anomalies.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension AnomaliesTest {
4343
return makeSequence(label: "nested", period: 0.02).map { (index, $0) }
4444
}
4545
.take(10)
46-
.mapWithIndex { ($1, $0.0, $0.1) }
46+
.enumerated().map { ($0, $1.0, $1.1) }
4747
.subscribe(
4848
onNext: { _ in },
4949
onCompleted: {

Tests/RxSwiftTests/Observable+MapTests.swift

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -172,185 +172,6 @@ extension ObservableMapTest {
172172
XCTAssertEqual(res.events, correctMessages)
173173
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
174174
}
175-
176-
func testMap1_Never() {
177-
let scheduler = TestScheduler(initialClock: 0)
178-
179-
let xs = scheduler.createHotObservable([
180-
next(150, 1),
181-
])
182-
183-
let res = scheduler.start { xs.mapWithIndex { ($0 + $1) * 2 } }
184-
185-
let correctMessages: [Recorded<Event<Int>>] = [
186-
]
187-
188-
let correctSubscriptions = [
189-
Subscription(200, 1000)
190-
]
191-
192-
XCTAssertEqual(res.events, correctMessages)
193-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
194-
}
195-
196-
func testMap1_Empty() {
197-
let scheduler = TestScheduler(initialClock: 0)
198-
199-
let xs = scheduler.createHotObservable([
200-
next(150, 1),
201-
completed(300)
202-
])
203-
204-
let res = scheduler.start { xs.mapWithIndex { ($0 + $1) * 2 } }
205-
206-
let correctMessages = [
207-
completed(300, Int.self)
208-
]
209-
210-
let correctSubscriptions = [
211-
Subscription(200, 300)
212-
]
213-
214-
XCTAssertEqual(res.events, correctMessages)
215-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
216-
}
217-
218-
func testMap1_Range() {
219-
let scheduler = TestScheduler(initialClock: 0)
220-
221-
let xs = scheduler.createHotObservable([
222-
next(150, 1),
223-
next(210, 5),
224-
next(220, 6),
225-
next(230, 7),
226-
next(240, 8),
227-
completed(300)
228-
])
229-
230-
let res = scheduler.start { xs.mapWithIndex { ($0 + $1) * 2 } }
231-
232-
let correctMessages = [
233-
next(210, (5 + 0) * 2),
234-
next(220, (6 + 1) * 2),
235-
next(230, (7 + 2) * 2),
236-
next(240, (8 + 3) * 2),
237-
completed(300)
238-
]
239-
240-
let correctSubscriptions = [
241-
Subscription(200, 300)
242-
]
243-
244-
XCTAssertEqual(res.events, correctMessages)
245-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
246-
}
247-
248-
func testMap1_Error() {
249-
let scheduler = TestScheduler(initialClock: 0)
250-
251-
let xs = scheduler.createHotObservable([
252-
next(150, 1),
253-
next(210, 5),
254-
next(220, 6),
255-
next(230, 7),
256-
next(240, 8),
257-
error(300, testError)
258-
])
259-
260-
let res = scheduler.start { xs.mapWithIndex { ($0 + $1) * 2 } }
261-
262-
let correctMessages = [
263-
next(210, (5 + 0) * 2),
264-
next(220, (6 + 1) * 2),
265-
next(230, (7 + 2) * 2),
266-
next(240, (8 + 3) * 2),
267-
error(300, testError)
268-
]
269-
270-
let correctSubscriptions = [
271-
Subscription(200, 300)
272-
]
273-
274-
XCTAssertEqual(res.events, correctMessages)
275-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
276-
}
277-
278-
func testMap1_Dispose() {
279-
let scheduler = TestScheduler(initialClock: 0)
280-
281-
let xs = scheduler.createHotObservable([
282-
next(150, 1),
283-
next(210, 5),
284-
next(220, 6),
285-
next(230, 7),
286-
next(240, 8),
287-
error(300, testError)
288-
])
289-
290-
let res = scheduler.start(disposed: 290) { xs.mapWithIndex { ($0 + $1) * 2 } }
291-
292-
let correctMessages = [
293-
next(210, (5 + 0) * 2),
294-
next(220, (6 + 1) * 2),
295-
next(230, (7 + 2) * 2),
296-
next(240, (8 + 3) * 2),
297-
]
298-
299-
let correctSubscriptions = [
300-
Subscription(200, 290)
301-
]
302-
303-
XCTAssertEqual(res.events, correctMessages)
304-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
305-
}
306-
307-
func testMap1_SelectorThrows() {
308-
let scheduler = TestScheduler(initialClock: 0)
309-
310-
let xs = scheduler.createHotObservable([
311-
next(150, 1),
312-
next(210, 5),
313-
next(220, 6),
314-
next(230, 7),
315-
next(240, 8),
316-
error(300, testError)
317-
])
318-
319-
let res = scheduler.start { xs.mapWithIndex { x, i throws -> Int in if x < 7 { return ((x + i) * 2) } else { throw testError } } }
320-
321-
let correctMessages = [
322-
next(210, (5 + 0) * 2),
323-
next(220, (6 + 1) * 2),
324-
error(230, testError)
325-
]
326-
327-
let correctSubscriptions = [
328-
Subscription(200, 230)
329-
]
330-
331-
XCTAssertEqual(res.events, correctMessages)
332-
XCTAssertEqual(xs.subscriptions, correctSubscriptions)
333-
}
334-
335-
func testMap_DisposeOnCompleted() {
336-
_ = Observable.just("A")
337-
.map { a in
338-
return a
339-
}
340-
.subscribe(onNext: { _ in
341-
342-
})
343-
}
344-
345-
func testMap1_DisposeOnCompleted() {
346-
_ = Observable.just("A")
347-
.mapWithIndex { (a, i) in
348-
return a
349-
}
350-
.subscribe(onNext: { _ in
351-
352-
})
353-
}
354175

355176
#if TRACE_RESOURCES
356177
func testMapReleasesResourcesOnComplete() {
@@ -364,18 +185,6 @@ extension ObservableMapTest {
364185
func testMap2ReleasesResourcesOnError() {
365186
_ = Observable<Int>.just(1).map { _ -> Bool in throw testError }.subscribe()
366187
}
367-
368-
func testMapWithIndexReleasesResourcesOnComplete() {
369-
_ = Observable<Int>.just(1).mapWithIndex { _, _ in true }.subscribe()
370-
}
371-
372-
func testMapWithIndex1ReleasesResourcesOnError() {
373-
_ = Observable<Int>.error(testError).mapWithIndex { _, _ in true }.subscribe()
374-
}
375-
376-
func testMapWithIndex2ReleasesResourcesOnError() {
377-
_ = Observable<Int>.just(1).mapWithIndex { _, _ -> Bool in throw testError }.subscribe()
378-
}
379188
#endif
380189
}
381190

0 commit comments

Comments
 (0)