| 1 | 
           efrain | 
           1 | 
           /**
  | 
        
        
            | 
            | 
           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+Validate.h"
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           #import "FBLPromisePrivate.h"
  | 
        
        
            | 
            | 
           20 | 
              | 
        
        
            | 
            | 
           21 | 
           @implementation FBLPromise (ValidateAdditions)
  | 
        
        
            | 
            | 
           22 | 
              | 
        
        
            | 
            | 
           23 | 
           - (FBLPromise*)validate:(FBLPromiseValidateWorkBlock)predicate {
  | 
        
        
            | 
            | 
           24 | 
             return [self onQueue:FBLPromise.defaultDispatchQueue validate:predicate];
  | 
        
        
            | 
            | 
           25 | 
           }
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           - (FBLPromise*)onQueue:(dispatch_queue_t)queue validate:(FBLPromiseValidateWorkBlock)predicate {
  | 
        
        
            | 
            | 
           28 | 
             NSParameterAssert(queue);
  | 
        
        
            | 
            | 
           29 | 
             NSParameterAssert(predicate);
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
             FBLPromiseChainedFulfillBlock chainedFulfill = ^id(id value) {
  | 
        
        
            | 
            | 
           32 | 
               return predicate(value) ? value :
  | 
        
        
            | 
            | 
           33 | 
                                         [[NSError alloc] initWithDomain:FBLPromiseErrorDomain
  | 
        
        
            | 
            | 
           34 | 
                                                                    code:FBLPromiseErrorCodeValidationFailure
  | 
        
        
            | 
            | 
           35 | 
                                                                userInfo:nil];
  | 
        
        
            | 
            | 
           36 | 
             };
  | 
        
        
            | 
            | 
           37 | 
             return [self chainOnQueue:queue chainedFulfill:chainedFulfill chainedReject:nil];
  | 
        
        
            | 
            | 
           38 | 
           }
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           @end
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
           @implementation FBLPromise (DotSyntax_ValidateAdditions)
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           - (FBLPromise* (^)(FBLPromiseValidateWorkBlock))validate {
  | 
        
        
            | 
            | 
           45 | 
             return ^(FBLPromiseValidateWorkBlock predicate) {
  | 
        
        
            | 
            | 
           46 | 
               return [self validate:predicate];
  | 
        
        
            | 
            | 
           47 | 
             };
  | 
        
        
            | 
            | 
           48 | 
           }
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
           - (FBLPromise* (^)(dispatch_queue_t, FBLPromiseValidateWorkBlock))validateOn {
  | 
        
        
            | 
            | 
           51 | 
             return ^(dispatch_queue_t queue, FBLPromiseValidateWorkBlock predicate) {
  | 
        
        
            | 
            | 
           52 | 
               return [self onQueue:queue validate:predicate];
  | 
        
        
            | 
            | 
           53 | 
             };
  | 
        
        
            | 
            | 
           54 | 
           }
  | 
        
        
            | 
            | 
           55 | 
              | 
        
        
            | 
            | 
           56 | 
           @end
  |