Skip to content

1.2 • Typed throws for `.unwrappedOrThrow()`

Latest
Compare
Choose a tag to compare
@KyLeggiero KyLeggiero released this 11 Oct 16:00
b02158c

This package's version 1.0 in 2019 simply contained .unwrappedOrThrow() and nothing else. The idea was simple: you place this after an Optional value, and if that value is nil, then it throws whatever error you give it, otherwise it returns that value. Like !/.unsafelyUnwrapped, but safer by using error-handling instead of potentially crashing.

Back then, there was no way to specify the type being thrown, and protocol-types weren't boxed the same if passed to something just taking that protocol's base type.

Now in Swift 6, not only is a bare protocol base type implicitly any, you can specify the type of a throws!

This release both uses the strong-generics typesystem to specify the type at compiletime, and also uses that type in the throws of this function!

All previous functionality and contracts remain exactly the same with this release; it just compiles much nicer and lets you use typed-throws. Hurray!