-
Notifications
You must be signed in to change notification settings - Fork 4
/
native_types.py
55 lines (39 loc) · 1.11 KB
/
native_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from type import NTypeVars, NGenericType
from enums import EnumType, EnumValue
list_generic = NGenericType("t")
n_list_type = NTypeVars("list", [list_generic])
map_key_generic = NGenericType("k")
map_value_generic = NGenericType("v")
n_map_type = NTypeVars("map", [map_key_generic, map_value_generic])
n_module_type = NTypeVars("module", [])
class NMap(dict):
def __init__(self, *args, **kw):
super(NMap, self).__init__(*args, **kw)
cmd_generic = NGenericType("t")
n_cmd_type = NTypeVars("cmd", [cmd_generic])
maybe_generic = NGenericType("t")
n_maybe_type = EnumType(
"maybe",
[
("yes", [maybe_generic]),
("none", []),
],
[maybe_generic],
)
none = EnumValue("none")
def yes(value):
return EnumValue("yes", [value])
result_ok_generic = NGenericType("o")
result_err_generic = NGenericType("e")
n_result_type = EnumType(
"result",
[
("ok", [result_ok_generic]),
("err", [result_err_generic]),
],
[result_ok_generic, result_err_generic],
)
def ok(value):
return EnumValue("ok", [value])
def err(value):
return EnumValue("err", [value])