unison/unison-src/transcripts/any-extract.md

24 lines
642 B
Markdown
Raw Permalink Normal View History

2021-09-10 23:49:15 +03:00
# Unit tests for Any.unsafeExtract
```ucm:hide
scratch/main> builtins.mergeio
scratch/main> load unison-src/transcripts-using-base/base.u
scratch/main> add
2021-09-10 23:49:15 +03:00
```
Any.unsafeExtract is a way to extract the value contained in an Any. This is unsafe because it allows the programmer to coerce a value into any type, which would cause undefined behaviour if used to coerce a value to the wrong type.
```unison
test> Any.unsafeExtract.works =
2021-09-10 23:49:15 +03:00
use Nat !=
checks [1 == Any.unsafeExtract (Any 1),
2021-09-10 23:49:15 +03:00
not (1 == Any.unsafeExtract (Any 2)),
(Some 1) == Any.unsafeExtract (Any (Some 1))
]
```
```ucm
scratch/main> add
2021-09-10 23:49:15 +03:00
```