1///|
2#external
3pub type Nullable[_]
4
5///|
6fn[T] type Nullable[_]
Nullable::_some(value : type parameter T
T) -> type Nullable[_]
Nullable[type parameter T
T] = "%identity"
7
8///|
9pub fn[T] type Nullable[_]
Nullable::(value : T) -> Nullable[T]
some(T
value : type parameter T
T) -> type Nullable[_]
Nullable[type parameter T
T] {
10 type Nullable[_]
Nullable::(value : T) -> Nullable[T]
_some(T
value).(self : Nullable[T]) -> Nullable[T]
cast()
11}
12
13///|
14fn[T] type Nullable[_]
Nullable::_unwrap(self : type Nullable[_]
Nullable[type parameter T
T]) -> type parameter T
T = "%identity"
15
16///|
17fn[T] type Nullable[_]
Nullable::(self : Nullable[T]) -> T
unwrap(Nullable[T]
self : type Nullable[_]
Nullable[type parameter T
T]) -> type parameter T
T {
18 Nullable[T]
self.(self : Nullable[T]) -> Nullable[T]
cast().(self : Nullable[T]) -> T
_unwrap()
19}
20
21///|
22extern "c" fn type Nullable[_]
Nullable::_none() -> type Nullable[_]
Nullable[Unit
Unit] = "moonbit_c_null"
23
24///|
25fn[T, U] type Nullable[_]
Nullable::_type_cast(self : type Nullable[_]
Nullable[type parameter T
T]) -> type Nullable[_]
Nullable[type parameter U
U] = "%identity"
26
27///|
28extern "c" fn type Nullable[_]
Nullable::_impl_cast(self : type Nullable[_]
Nullable[Unit
Unit]) -> type Nullable[_]
Nullable[Unit
Unit] = "moonbit_c_identity"
29
30///|
31fn[T, U] type Nullable[_]
Nullable::(self : Nullable[T]) -> Nullable[U]
cast(Nullable[T]
self : type Nullable[_]
Nullable[type parameter T
T]) -> type Nullable[_]
Nullable[type parameter U
U] {
32 Nullable[T]
self.(self : Nullable[T]) -> Nullable[Unit]
_type_cast().(self : Nullable[Unit]) -> Nullable[Unit]
_impl_cast().(self : Nullable[Unit]) -> Nullable[U]
_type_cast()
33}
34
35///|
36pub fn[T] type Nullable[_]
Nullable::() -> Nullable[T]
none() -> type Nullable[_]
Nullable[type parameter T
T] {
37 type Nullable[_]
Nullable::() -> Nullable[Unit]
_none().(self : Nullable[Unit]) -> Nullable[T]
cast()
38}
39
40///|
41pub fn[T] () -> Nullable[T]
none() -> type Nullable[_]
Nullable[type parameter T
T] {
42 type Nullable[_]
Nullable::() -> Nullable[Unit]
_none().(self : Nullable[Unit]) -> Nullable[T]
cast()
43}
44
45///|
46extern "c" fn type Nullable[_]
Nullable::_is_null(self : type Nullable[_]
Nullable[Unit
Unit]) -> Bool
Bool = "moonbit_c_is_null"
47
48///|
49pub fn[T] type Nullable[_]
Nullable::(self : Nullable[T]) -> Bool
is_null(Nullable[T]
self : type Nullable[_]
Nullable[type parameter T
T]) -> Bool
Bool {
50 Nullable[T]
self.(self : Nullable[T]) -> Nullable[Unit]
cast().(self : Nullable[Unit]) -> Bool
_is_null()
51}
52
53///|
54pub fn[T] type Nullable[_]
Nullable::(option : T?) -> Nullable[T]
of(T?
option : type parameter T
T?) -> type Nullable[_]
Nullable[type parameter T
T] {
55 match T?
option {
56 (T) -> T?
Some(T
value) => type Nullable[_]
Nullable::(value : T) -> Nullable[T]
some(T
value)
57 T?
None => type Nullable[_]
Nullable::() -> Nullable[T]
none()
58 }
59}
60
61///|
62pub fn[T] type Nullable[_]
Nullable::(self : Nullable[T]) -> T?
to(Nullable[T]
self : type Nullable[_]
Nullable[type parameter T
T]) -> type parameter T
T? {
63 if Nullable[T]
self.(self : Nullable[T]) -> Bool
is_null() {
64 return T?
None
65 } else {
66 return (T) -> T?
Some(Nullable[T]
self.(self : Nullable[T]) -> T
unwrap())
67 }
68}
69