From bebd010673218c252b43aede96d3fc5717519dc7 Mon Sep 17 00:00:00 2001 From: Max Moiseev Date: Tue, 27 Jun 2017 14:45:15 -0700 Subject: [PATCH] [NOT FOR MERGE][stdlib] Adding a variant of ??, with a Never returning closure --- stdlib/public/core/Optional.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/public/core/Optional.swift b/stdlib/public/core/Optional.swift index b694cdb91ee7f..a1bd5a83535b8 100644 --- a/stdlib/public/core/Optional.swift +++ b/stdlib/public/core/Optional.swift @@ -675,6 +675,17 @@ public func ?? (optional: T?, defaultValue: @autoclosure () throws -> T?) } } +@_transparent +public func ?? (optional: T?, defaultValue: @autoclosure () throws -> Never) + rethrows -> T { + switch optional { + case .some(let value): + return value + case .none: + try defaultValue() + } +} + extension Optional { @available(*, unavailable, renamed: "none")