Closed KtorZ closed 2 months ago
We want to provide ways to safely cast between types similar to expect, but without crashing the entire program on failure.
expect
This could be introduced via a new syntax, to not overload expect from its current semantic. Something along the lines of:
if unknown is Foo { ... } else if unknown is Bar { ... } else { ... }
where Foo and Bar are type annotations. Within each branch, the type of unknown would be respectively Foo, Bar and Data.
Foo
Bar
unknown
Data
This is particularly useful for casting from an unknown type (i.e. Data) from within an iterator (e.g. foldr).
foldr
Alternative right now requires a lot of boilerplate and the explicit use of builtin functions such as choose_data.
choose_data
What is your idea? Provide a use case.
We want to provide ways to safely cast between types similar to
expect
, but without crashing the entire program on failure.This could be introduced via a new syntax, to not overload
expect
from its current semantic. Something along the lines of:where
Foo
andBar
are type annotations. Within each branch, the type ofunknown
would be respectivelyFoo
,Bar
andData
.Why is it a good idea?
This is particularly useful for casting from an unknown type (i.e.
Data
) from within an iterator (e.g.foldr
).What is the current alternative and why is it not good enough?
Alternative right now requires a lot of boilerplate and the explicit use of builtin functions such as
choose_data
.