Merge pull request #8376 from ProofOfKeags/feature/unsafe-from-some

fn: add UnsafeFromSome to Option API
This commit is contained in:
Olaoluwa Osuntokun 2024-01-11 17:22:33 -08:00 committed by GitHub
commit ba1725f161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,3 +147,12 @@ func (o Option[A]) Alt(o2 Option[A]) Option[A] {
return o2
}
// UnsafeFromSome can be used to extract the internal value. This will panic
// if the value is None() though.
func (o Option[A]) UnsafeFromSome() A {
if o.isSome {
return o.some
}
panic("Option was None()")
}