RACEmptySequence.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // RACEmptySequence.m
  3. // ReactiveObjC
  4. //
  5. // Created by Justin Spahr-Summers on 2012-10-29.
  6. // Copyright (c) 2012 GitHub. All rights reserved.
  7. //
  8. #import "RACEmptySequence.h"
  9. @implementation RACEmptySequence
  10. #pragma mark Lifecycle
  11. + (instancetype)empty {
  12. static id singleton;
  13. static dispatch_once_t pred;
  14. dispatch_once(&pred, ^{
  15. singleton = [[self alloc] init];
  16. });
  17. return singleton;
  18. }
  19. #pragma mark RACSequence
  20. - (id)head {
  21. return nil;
  22. }
  23. - (RACSequence *)tail {
  24. return nil;
  25. }
  26. - (RACSequence *)bind:(RACStreamBindBlock)bindBlock passingThroughValuesFromSequence:(RACSequence *)passthroughSequence {
  27. return passthroughSequence ?: self;
  28. }
  29. #pragma mark NSCoding
  30. - (Class)classForCoder {
  31. // Empty sequences should be encoded as themselves, not array sequences.
  32. return self.class;
  33. }
  34. - (instancetype)initWithCoder:(NSCoder *)coder {
  35. // Return the singleton.
  36. return self.class.empty;
  37. }
  38. - (void)encodeWithCoder:(NSCoder *)coder {
  39. }
  40. #pragma mark NSObject
  41. - (NSString *)description {
  42. return [NSString stringWithFormat:@"<%@: %p>{ name = %@ }", self.class, self, self.name];
  43. }
  44. - (NSUInteger)hash {
  45. // This hash isn't ideal, but it's better than -[RACSequence hash], which
  46. // would just be zero because we have no head.
  47. return (NSUInteger)(__bridge void *)self;
  48. }
  49. - (BOOL)isEqual:(RACSequence *)seq {
  50. return (self == seq);
  51. }
  52. @end