unison/unison-src/transcripts/any-extract.md
2021-09-10 13:49:15 -07:00

613 B

Unit tests for Any.unsafeExtract

.> builtins.merge
.> cd builtin
.> load unison-src/transcripts-using-base/base.u
.> add

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.


test> Any.unsafeExtract.works = 
  use Nat !=
  checks [1 == Any.unsafeExtract (Any 1), 
          not (1 == Any.unsafeExtract (Any 2)),
          (Some 1) == Any.unsafeExtract (Any (Some 1))
         ]
.> add