commit | author | age
|
a6c014
|
1 |
/** |
L |
2 |
Copyright 2018 Google Inc. All rights reserved. |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at: |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
*/ |
|
16 |
|
|
17 |
#import "FBLPromise.h" |
|
18 |
|
|
19 |
NS_ASSUME_NONNULL_BEGIN |
|
20 |
|
|
21 |
@interface FBLPromise<Value>(ReduceAdditions) |
|
22 |
|
|
23 |
typedef id __nullable (^FBLPromiseReducerBlock)(Value __nullable partial, id next) |
|
24 |
NS_SWIFT_UNAVAILABLE(""); |
|
25 |
|
|
26 |
/** |
|
27 |
Sequentially reduces a collection of values to a single promise using a given combining block |
|
28 |
and the value `self` resolves with as initial value. |
|
29 |
|
|
30 |
@param items An array of values to process in order. |
|
31 |
@param reducer A block to combine an accumulating value and an element of the sequence into |
|
32 |
the new accumulating value or a promise resolved with it, to be used in the next |
|
33 |
call of the `reducer` or returned to the caller. |
|
34 |
@return A new pending promise returned from the last `reducer` invocation. |
|
35 |
Or `self` if `items` is empty. |
|
36 |
*/ |
|
37 |
- (FBLPromise *)reduce:(NSArray *)items |
|
38 |
combine:(FBLPromiseReducerBlock)reducer NS_SWIFT_UNAVAILABLE(""); |
|
39 |
|
|
40 |
/** |
|
41 |
Sequentially reduces a collection of values to a single promise using a given combining block |
|
42 |
and the value `self` resolves with as initial value. |
|
43 |
|
|
44 |
@param queue A queue to dispatch on. |
|
45 |
@param items An array of values to process in order. |
|
46 |
@param reducer A block to combine an accumulating value and an element of the sequence into |
|
47 |
the new accumulating value or a promise resolved with it, to be used in the next |
|
48 |
call of the `reducer` or returned to the caller. |
|
49 |
@return A new pending promise returned from the last `reducer` invocation. |
|
50 |
Or `self` if `items` is empty. |
|
51 |
*/ |
|
52 |
- (FBLPromise *)onQueue:(dispatch_queue_t)queue |
|
53 |
reduce:(NSArray *)items |
|
54 |
combine:(FBLPromiseReducerBlock)reducer NS_SWIFT_UNAVAILABLE(""); |
|
55 |
|
|
56 |
@end |
|
57 |
|
|
58 |
/** |
|
59 |
Convenience dot-syntax wrappers for `FBLPromise` `reduce` operators. |
|
60 |
Usage: promise.reduce(values, ^id(id partial, id next) { ... }) |
|
61 |
*/ |
|
62 |
@interface FBLPromise<Value>(DotSyntax_ReduceAdditions) |
|
63 |
|
|
64 |
- (FBLPromise * (^)(NSArray *, FBLPromiseReducerBlock))reduce FBL_PROMISES_DOT_SYNTAX |
|
65 |
NS_SWIFT_UNAVAILABLE(""); |
|
66 |
- (FBLPromise * (^)(dispatch_queue_t, NSArray *, FBLPromiseReducerBlock))reduceOn |
|
67 |
FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE(""); |
|
68 |
|
|
69 |
@end |
|
70 |
|
|
71 |
NS_ASSUME_NONNULL_END |