You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.7 KiB

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