feat: add UniqueType.unwrap_or()
This commit is contained in:
parent
2cc15bf250
commit
fee08f3609
1 changed files with 5 additions and 0 deletions
|
|
@ -49,6 +49,11 @@ class UniqueType(type):
|
|||
raise TypeError(f"{cls} not unwrapped")
|
||||
return value # type: ignore
|
||||
|
||||
def unwrap_or(cls: type[T], value: V | type[T] | T, default: R, /) -> V | R:
|
||||
if value is cls or isinstance(value, cls):
|
||||
return default
|
||||
return value # type: ignore
|
||||
|
||||
def map(
|
||||
cls: type[T],
|
||||
value: V | type[T] | T,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue