Skip to content

Instantly share code, notes, and snippets.

@danielctull
Last active June 1, 2022 08:58
Show Gist options
  • Save danielctull/40e4fcc5fc3f70980ea582a1cced4e7d to your computer and use it in GitHub Desktop.
Save danielctull/40e4fcc5fc3f70980ea582a1cced4e7d to your computer and use it in GitHub Desktop.
I think I found the perfect improvement for force unwrapping in swift.
// EXAMPLE
let string: String? = "Hello World" // String?
let unwrappedString = string.really.srsly.itsfine.honestly.aaarggh // String
print(unwrappedString)
// IMPLEMENTATION
extension Optional {
var really: Really<Wrapped> {
Really(srsly: Srsly(itsfine: ItsFine(honestly: Honestly(aaarggh: { self! }))))
}
}
struct Really<Value> {
let srsly: Srsly<Value>
}
struct Srsly<Value> {
let itsfine: ItsFine<Value>
}
struct ItsFine<Value> {
let honestly: Honestly<Value>
}
struct Honestly<Value> {
var aaarggh: Value { getAaarggh() }
private let getAaarggh: () -> Value
init(aaarggh: @escaping () -> Value) {
getAaarggh = aaarggh
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment