summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-09-14 10:59:09 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-09-15 10:58:43 +0200
commit8c8bbadd89fb9aa7cb705488b835567ffaa3c74b (patch)
tree1ddd3d90e85db1f1ed7125cd25ee4cbce6e680df /ios
parentfedea0de95f2a64c3274049ecb9fc32cf902f59f (diff)
downloadmullvadvpn-8c8bbadd89fb9aa7cb705488b835567ffaa3c74b.tar.xz
mullvadvpn-8c8bbadd89fb9aa7cb705488b835567ffaa3c74b.zip
Promise: add `some(or: Failure)` extension
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/Promise/Promise+Optional.swift7
1 files changed, 7 insertions, 0 deletions
diff --git a/ios/MullvadVPN/Promise/Promise+Optional.swift b/ios/MullvadVPN/Promise/Promise+Optional.swift
index 0fc38a1ae6..eca39ae3e6 100644
--- a/ios/MullvadVPN/Promise/Promise+Optional.swift
+++ b/ios/MullvadVPN/Promise/Promise+Optional.swift
@@ -28,4 +28,11 @@ extension Promise where Value: AnyOptional {
return value.asConcreteType().map(producePromise) ?? .resolved(defaultValue)
}
}
+
+ /// Map contained value to result providing failure when the value is `nil`.
+ func some<Failure: Error>(or failure: Failure) -> Result<Value.Wrapped, Failure>.Promise {
+ return then { value -> Result<Value.Wrapped, Failure> in
+ return value.asConcreteType().map { .success($0) } ?? .failure(failure)
+ }
+ }
}