diff --git a/Sources/YData/Core/Optional.swift b/Sources/YData/Core/Optional.swift index 83d80a0..3f382a4 100644 --- a/Sources/YData/Core/Optional.swift +++ b/Sources/YData/Core/Optional.swift @@ -12,4 +12,12 @@ extension Optional { left = right } } + + public func tryMap(_ closure: (() -> E)) throws -> Wrapped { + guard let value = wrapped else { + throw closure() + } + + return value + } }