FImmutableTree.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2017 Google
  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. #import "FImmutableSortedDictionary.h"
  17. #import "FPath.h"
  18. #import "FTuplePathValue.h"
  19. @interface FImmutableTree : NSObject
  20. - (id) initWithValue:(id)aValue;
  21. - (id) initWithValue:(id)aValue children:(FImmutableSortedDictionary *)childrenMap;
  22. + (FImmutableTree *) empty;
  23. - (BOOL) isEmpty;
  24. - (FTuplePathValue *) findRootMostMatchingPath:(FPath *)relativePath predicate:(BOOL (^)(id))predicate;
  25. - (FTuplePathValue *) findRootMostValueAndPath:(FPath *)relativePath;
  26. - (FImmutableTree *) subtreeAtPath:(FPath *)relativePath;
  27. - (FImmutableTree *) setValue:(id)newValue atPath:(FPath *)relativePath;
  28. - (FImmutableTree *) removeValueAtPath:(FPath *)relativePath;
  29. - (id) valueAtPath:(FPath *)relativePath;
  30. - (id) rootMostValueOnPath:(FPath *)path;
  31. - (id) rootMostValueOnPath:(FPath *)path matching:(BOOL (^)(id))predicate;
  32. - (id) leafMostValueOnPath:(FPath *)path;
  33. - (id) leafMostValueOnPath:(FPath *)relativePath matching:(BOOL (^)(id))predicate;
  34. - (BOOL) containsValueMatching:(BOOL (^)(id))predicate;
  35. - (FImmutableTree *) setTree:(FImmutableTree *)newTree atPath:(FPath *)relativePath;
  36. - (id) foldWithBlock:(id (^)(FPath *path, id value, NSDictionary *foldedChildren))block;
  37. - (id) findOnPath:(FPath *)path andApplyBlock:(id (^)(FPath *path, id value))block;
  38. - (FPath *) forEachOnPath:(FPath *)path whileBlock:(BOOL (^)(FPath *path, id value))block;
  39. - (FImmutableTree *) forEachOnPath:(FPath *)path performBlock:(void (^)(FPath *path, id value))block;
  40. - (void) forEach:(void (^)(FPath *path, id value))block;
  41. - (void) forEachChild:(void (^)(NSString *childKey, id childValue))block;
  42. @property (nonatomic, strong, readonly) id value;
  43. @property (nonatomic, strong, readonly) FImmutableSortedDictionary *children;
  44. @end