@@ -10,8 +10,70 @@ string_meta.__add = function(v1, v2)
10
10
return v1 + v2
11
11
end
12
12
13
- local str = tostring
13
+ local g_real_unpack = unpack or table.unpack
14
+
15
+ local unpack = function (t )
16
+ if type (t ) == " table" and t .is_list then
17
+ return g_real_unpack (t ._data )
18
+ end
19
+ return g_real_unpack (t )
20
+ end
21
+
22
+ local abs = math.abs
23
+ local ascii = string.byte
24
+ local chr = string.char
14
25
local int = tonumber
26
+ local str = tostring
27
+
28
+ local function all (iterable )
29
+ for element in iterable do
30
+ if not element then
31
+ return false
32
+ end
33
+ end
34
+ return true
35
+ end
36
+
37
+ local function any (iterable )
38
+ for element in iterable do
39
+ if element then
40
+ return true
41
+ end
42
+ end
43
+ return false
44
+ end
45
+
46
+ local function bool (x )
47
+ if x == false or x == nil or x == 0 then
48
+ return false
49
+ end
50
+
51
+ if type (x ) == " table" then
52
+ if x .is_list or x .is_dict then
53
+ return next (x ._data ) ~= nil
54
+ end
55
+ end
56
+
57
+ return true
58
+ end
59
+
60
+ local function callable (x )
61
+ local x_type = type (x )
62
+ if x_type == " function" then
63
+ return true
64
+ end
65
+ if x_type == " table" then
66
+ local meta = getmetatable (x )
67
+ return type (meta .__call ) == " function"
68
+ end
69
+
70
+ return false
71
+ end
72
+
73
+ local function divmod (a , b )
74
+ local res = { math.floor (a / b ), math.fmod (a , b ) }
75
+ return unpack (res )
76
+ end
15
77
16
78
local function len (t )
17
79
if type (t ._data ) == " table" then
@@ -65,15 +127,6 @@ local function enumerate(t, start)
65
127
end
66
128
end
67
129
68
- local g_real_unpack = unpack or table.unpack
69
-
70
- local unpack = function (t )
71
- if type (t ) == " table" and t .is_list then
72
- return g_real_unpack (t ._data )
73
- end
74
- return g_real_unpack (t )
75
- end
76
-
77
130
local list = {}
78
131
setmetatable (list , {
79
132
__call = function (_ , t )
0 commit comments