|
| 1 | +import Result |
| 2 | + |
| 3 | +// Observation |
| 4 | +extension SignalProducer where Value == Never { |
| 5 | + @discardableResult |
| 6 | + @available(*, deprecated, message:"`Result.success` is never delivered - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 7 | + public func startWithResult(_ action: @escaping (Result<Value, Error>) -> Void) -> Disposable { observingInhabitableTypeError() } |
| 8 | + |
| 9 | + @discardableResult |
| 10 | + @available(*, deprecated, message:"Observer is never called - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 11 | + public func startWithValues(_ action: @escaping (Value) -> Void) -> Disposable { observingInhabitableTypeError() } |
| 12 | +} |
| 13 | + |
| 14 | +extension SignalProducer where Value == Never, Error == NoError { |
| 15 | + @discardableResult |
| 16 | + @available(*, deprecated, message:"Observer is never called - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 17 | + public func startWithResult(_ action: @escaping (Result<Value, Error>) -> Void) -> Disposable { observingInhabitableTypeError() } |
| 18 | +} |
| 19 | + |
| 20 | +extension SignalProducer where Error == NoError { |
| 21 | + @discardableResult |
| 22 | + @available(*, deprecated, message:"`Error` is inhabitable so the observer is never called (Instantiation at runtime would trap)") |
| 23 | + public func startWithFailed(_ action: @escaping (Error) -> Void) -> Disposable { observingInhabitableTypeError() } |
| 24 | +} |
| 25 | + |
| 26 | +extension Signal where Value == Never { |
| 27 | + @discardableResult |
| 28 | + @available(*, deprecated, message:"`Result.success` is never delivered - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 29 | + public func observeResult(_ action: @escaping (Result<Value, Error>) -> Void) -> Disposable? { observingInhabitableTypeError() } |
| 30 | + |
| 31 | + @discardableResult |
| 32 | + @available(*, deprecated, message:"Observer is never called - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 33 | + public func observeValues(_ action: @escaping (Value) -> Void) -> Disposable? { observingInhabitableTypeError() } |
| 34 | +} |
| 35 | + |
| 36 | +extension Signal where Value == Never, Error == NoError { |
| 37 | + @discardableResult |
| 38 | + @available(*, deprecated, message:"Observer is never called - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 39 | + public func observeResult(_ action: @escaping (Result<Value, Error>) -> Void) -> Disposable? { observingInhabitableTypeError() } |
| 40 | +} |
| 41 | + |
| 42 | +extension Signal where Error == NoError { |
| 43 | + @discardableResult |
| 44 | + @available(*, deprecated, message:"Observer is never invoked - `Error` is inhabitable (Instantiation at runtime would trap)") |
| 45 | + public func observeFailed(_ action: @escaping (Error) -> Void) -> Disposable? { observingInhabitableTypeError() } |
| 46 | +} |
| 47 | + |
| 48 | +// flatMap |
| 49 | +extension SignalProducer where Value == Never { |
| 50 | + @discardableResult |
| 51 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 52 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Error> where Inner.Error == Error { observingInhabitableTypeError() } |
| 53 | + |
| 54 | + @discardableResult |
| 55 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 56 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Error> where Inner.Error == NoError { observingInhabitableTypeError() } |
| 57 | +} |
| 58 | + |
| 59 | +extension SignalProducer where Value == Never, Error == NoError { |
| 60 | + @discardableResult |
| 61 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 62 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Inner.Error> { observingInhabitableTypeError() } |
| 63 | + |
| 64 | + @discardableResult |
| 65 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 66 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Inner.Error> where Inner.Error == Error { observingInhabitableTypeError() } |
| 67 | +} |
| 68 | + |
| 69 | +extension SignalProducer where Error == NoError { |
| 70 | + @discardableResult |
| 71 | + @available(*, deprecated, message:"Use `promoteError` instead - `Error` is inhabitable (Instantiation at runtime would trap)") |
| 72 | + public func flatMapError<NewError>(_ transform: @escaping (Error) -> SignalProducer<Value, NewError>) -> SignalProducer<Value, NewError> { observingInhabitableTypeError() } |
| 73 | +} |
| 74 | + |
| 75 | +extension Signal where Value == Never { |
| 76 | + @discardableResult |
| 77 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 78 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> Signal<Inner.Value, Error> where Inner.Error == Error { observingInhabitableTypeError() } |
| 79 | + |
| 80 | + @discardableResult |
| 81 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` is inhabitable (Instantiation at runtime would trap)") |
| 82 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> Signal<Inner.Value, Error> where Inner.Error == NoError { observingInhabitableTypeError() } |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | +extension Signal where Value == Never, Error == NoError { |
| 87 | + @discardableResult |
| 88 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 89 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> Signal<Inner.Value, Inner.Error> { observingInhabitableTypeError() } |
| 90 | + |
| 91 | + @discardableResult |
| 92 | + @available(*, deprecated, message:"Use `promoteValue` instead - `Value` and `Error` are inhabitable (Instantiation at runtime would trap)") |
| 93 | + public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> Signal<Inner.Value, Inner.Error> where Inner.Error == Error { observingInhabitableTypeError() } |
| 94 | +} |
| 95 | + |
| 96 | +extension Signal where Error == NoError { |
| 97 | + @discardableResult |
| 98 | + @available(*, deprecated, message:"Use `promoteError` instead - `Error` is inhabitable (Instantiation at runtime would trap)") |
| 99 | + public func flatMapError<NewError>(_ transform: @escaping (Error) -> SignalProducer<Value, NewError>) -> Signal<Value, NewError> { observingInhabitableTypeError() } |
| 100 | +} |
| 101 | + |
| 102 | +@inline(never) |
| 103 | +private func observingInhabitableTypeError() -> Never { |
| 104 | + fatalError("Detected an attempt to instantiate a `Signal` or `SignalProducer` that observes an inhabitable type, e.g. `Never` or `NoError`. This is considered a logical error, and appropriate operators should be used instead. Please refer to the warnings raised by the compiler.") |
| 105 | +} |
| 106 | + |
| 107 | +/* |
| 108 | +func test() { |
| 109 | + SignalProducer<Never, AnyError>.never.startWithResult { _ in } |
| 110 | + SignalProducer<Never, NoError>.never.startWithResult { _ in } |
| 111 | + SignalProducer<Any, NoError>.never.startWithFailed { _ in } |
| 112 | + SignalProducer<Never, NoError>.never.startWithFailed { _ in } |
| 113 | + Signal<Never, AnyError>.never.observeResult { _ in } |
| 114 | + Signal<Never, NoError>.never.observeResult { _ in } |
| 115 | + Signal<Any, NoError>.never.observeFailed { _ in } |
| 116 | + Signal<Never, NoError>.never.observeFailed { _ in } |
| 117 | + |
| 118 | + SignalProducer<Never, AnyError>.never.flatMap(.latest) { _ in SignalProducer<Int, AnyError>.empty } |
| 119 | + SignalProducer<Never, AnyError>.never.flatMap(.latest) { _ in SignalProducer<Int, NoError>.empty } |
| 120 | + SignalProducer<Never, NoError>.never.flatMap(.latest) { _ in SignalProducer<Int, AnyError>.empty } |
| 121 | + SignalProducer<Never, NoError>.never.flatMap(.latest) { _ in SignalProducer<Int, NoError>.empty } |
| 122 | + SignalProducer<Never, NoError>.never.flatMapError { _ in SignalProducer<Never, AnyError>.empty } |
| 123 | + SignalProducer<Never, NoError>.never.flatMapError { _ in SignalProducer<Never, NoError>.empty } |
| 124 | + |
| 125 | + Signal<Never, AnyError>.never.flatMap(.latest) { _ in SignalProducer<Int, AnyError>.empty } |
| 126 | + Signal<Never, AnyError>.never.flatMap(.latest) { _ in SignalProducer<Int, NoError>.empty } |
| 127 | + Signal<Never, NoError>.never.flatMap(.latest) { _ in SignalProducer<Int, AnyError>.empty } |
| 128 | + Signal<Never, NoError>.never.flatMap(.latest) { _ in SignalProducer<Int, NoError>.empty } |
| 129 | + Signal<Never, NoError>.never.flatMapError { _ in SignalProducer<Never, AnyError>.empty } |
| 130 | + Signal<Never, NoError>.never.flatMapError { _ in SignalProducer<Never, NoError>.empty } |
| 131 | +} |
| 132 | +*/ |
0 commit comments