summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
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)
+ }
+ }
}