gandora-std 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gandora_std-0.2.1 → gandora_std-0.2.2}/PKG-INFO +2 -2
- {gandora_std-0.2.1 → gandora_std-0.2.2}/gandora.jsonc +1 -1
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/enum.py +26 -39
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/gandora.toml +1 -1
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/keyword.py +4 -6
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/list.py +4 -6
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/map.py +8 -12
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/string.py +8 -12
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pyproject.toml +2 -2
- {gandora_std-0.2.1 → gandora_std-0.2.2}/.gitignore +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/_gan/gandora_std/enum.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/_gan/gandora_std/keyword.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/_gan/gandora_std/list.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/_gan/gandora_std/map.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/pkg/gandora_std/_gan/gandora_std/string.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/src/enum.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/src/keyword.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/src/list.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/src/map.gan +0 -0
- {gandora_std-0.2.1 → gandora_std-0.2.2}/src/string.gan +0 -0
|
@@ -22,9 +22,8 @@ def _gan_rem(a, b):
|
|
|
22
22
|
def map(xs, f):
|
|
23
23
|
"""Applies `f` to every element.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[10, 20, 30]
|
|
25
|
+
>>> map([1, 2, 3], lambda x: x * 10)
|
|
26
|
+
[10, 20, 30]
|
|
28
27
|
"""
|
|
29
28
|
return builtins.list(builtins.map(f, xs))
|
|
30
29
|
|
|
@@ -32,9 +31,8 @@ def map(xs, f):
|
|
|
32
31
|
def filter(xs, f):
|
|
33
32
|
"""Keeps elements for which `f` is truthy.
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[2, 4]
|
|
34
|
+
>>> filter([1, 2, 3, 4], lambda x: _gan_rem(x, 2) == 0)
|
|
35
|
+
[2, 4]
|
|
38
36
|
"""
|
|
39
37
|
return ([x for x in (xs) if (f)(x)])
|
|
40
38
|
|
|
@@ -47,9 +45,8 @@ def reject(xs, f):
|
|
|
47
45
|
def reduce(xs, acc, f):
|
|
48
46
|
"""Folds left with Elixir argument order: `f` receives (element, acc).
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
10
|
|
48
|
+
>>> reduce([1, 2, 3, 4], 0, lambda x, acc: acc + x)
|
|
49
|
+
10
|
|
53
50
|
"""
|
|
54
51
|
return functools.reduce(lambda a, x: f(x, a), xs, acc)
|
|
55
52
|
|
|
@@ -72,9 +69,8 @@ def sort(xs):
|
|
|
72
69
|
def sort_by(xs, f):
|
|
73
70
|
"""Sorts by the key computed by `f` (Python `key=`, not a comparator).
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
['a', 'bb', 'ccc']
|
|
72
|
+
>>> sort_by(["ccc", "a", "bb"], lambda s: gandora_std.string.length(s))
|
|
73
|
+
['a', 'bb', 'ccc']
|
|
78
74
|
"""
|
|
79
75
|
return builtins.sorted(xs, key=f)
|
|
80
76
|
|
|
@@ -87,9 +83,8 @@ def reverse(xs):
|
|
|
87
83
|
def join(xs, sep):
|
|
88
84
|
"""Joins elements (converted by `to_string`) with `sep`.
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
'1-2-3'
|
|
86
|
+
>>> join([1, 2, 3], "-")
|
|
87
|
+
'1-2-3'
|
|
93
88
|
"""
|
|
94
89
|
return sep.join(([str(x) for x in (xs)]))
|
|
95
90
|
|
|
@@ -120,9 +115,8 @@ def zip(xs, ys):
|
|
|
120
115
|
def with_index(xs):
|
|
121
116
|
"""Each element paired with its index: `{element, index}`.
|
|
122
117
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
[('a', 0), ('b', 1)]
|
|
118
|
+
>>> with_index(["a", "b"])
|
|
119
|
+
[('a', 0), ('b', 1)]
|
|
126
120
|
"""
|
|
127
121
|
return ([(x, i) for i, x in enumerate((xs))])
|
|
128
122
|
|
|
@@ -155,9 +149,8 @@ def uniq(xs):
|
|
|
155
149
|
def flat_map(xs, f):
|
|
156
150
|
"""Maps `f` (which returns a list) and concatenates the results.
|
|
157
151
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
[1, 10, 2, 20]
|
|
152
|
+
>>> flat_map([1, 2], lambda x: [x, x * 10])
|
|
153
|
+
[1, 10, 2, 20]
|
|
161
154
|
"""
|
|
162
155
|
return ([y for x in (xs) for y in (f)(x)])
|
|
163
156
|
|
|
@@ -181,9 +174,8 @@ def max(xs):
|
|
|
181
174
|
def find(xs, f):
|
|
182
175
|
"""The first element for which `f` is truthy, or nil.
|
|
183
176
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
3
|
|
177
|
+
>>> find([1, 2, 3, 4], lambda x: x > 2)
|
|
178
|
+
3
|
|
187
179
|
"""
|
|
188
180
|
return (next((x for x in (xs) if (f)(x)), None))
|
|
189
181
|
|
|
@@ -196,9 +188,8 @@ def find_index(xs, f):
|
|
|
196
188
|
def frequencies(xs):
|
|
197
189
|
"""A map from each distinct element to its occurrence count.
|
|
198
190
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
{'a': 2, 'b': 1}
|
|
191
|
+
>>> frequencies(["a", "b", "a"])
|
|
192
|
+
{'a': 2, 'b': 1}
|
|
202
193
|
"""
|
|
203
194
|
return builtins.dict(collections.Counter(xs))
|
|
204
195
|
|
|
@@ -206,9 +197,8 @@ def frequencies(xs):
|
|
|
206
197
|
def group_by(xs, f):
|
|
207
198
|
"""Groups elements by the key computed by `f`, preserving order.
|
|
208
199
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
{1: [1, 3, 5], 0: [2, 4]}
|
|
200
|
+
>>> group_by([1, 2, 3, 4, 5], lambda x: _gan_rem(x, 2))
|
|
201
|
+
{1: [1, 3, 5], 0: [2, 4]}
|
|
212
202
|
"""
|
|
213
203
|
return ({k: [x for x in (xs) if (f)(x) == k] for k in dict.fromkeys((f)(x) for x in (xs))})
|
|
214
204
|
|
|
@@ -241,9 +231,8 @@ def drop_while(xs, f):
|
|
|
241
231
|
def chunk_every(xs, n):
|
|
242
232
|
"""Splits into chunks of `n` elements; the last chunk may be shorter.
|
|
243
233
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
[[1, 2], [3, 4], [5]]
|
|
234
|
+
>>> chunk_every([1, 2, 3, 4, 5], 2)
|
|
235
|
+
[[1, 2], [3, 4], [5]]
|
|
247
236
|
"""
|
|
248
237
|
return ([(xs)[i:i + (n)] for i in range(0, len((xs)), (n))])
|
|
249
238
|
|
|
@@ -256,9 +245,8 @@ def concat(xss):
|
|
|
256
245
|
def intersperse(xs, sep):
|
|
257
246
|
"""Puts `sep` between every two elements.
|
|
258
247
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
[1, 'x', 2, 'x', 3]
|
|
248
|
+
>>> intersperse([1, 2, 3], "x")
|
|
249
|
+
[1, 'x', 2, 'x', 3]
|
|
262
250
|
"""
|
|
263
251
|
return ([v for x in (xs) for v in (x, (sep))][:-1])
|
|
264
252
|
|
|
@@ -271,8 +259,7 @@ def slice(xs, start, count):
|
|
|
271
259
|
def dedup(xs):
|
|
272
260
|
"""Collapses consecutive duplicate elements.
|
|
273
261
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
[1, 2, 1]
|
|
262
|
+
>>> dedup([1, 1, 2, 2, 2, 1])
|
|
263
|
+
[1, 2, 1]
|
|
277
264
|
"""
|
|
278
265
|
return ([x for i, x in enumerate((xs)) if i == 0 or x != (xs)[i - 1]])
|
|
@@ -10,9 +10,8 @@ class GanMatchError(Exception):
|
|
|
10
10
|
def get(kw, key):
|
|
11
11
|
"""The first value for `key`, or nil.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
1
|
|
13
|
+
>>> get([("a", 1), ("b", 2)], "a")
|
|
14
|
+
1
|
|
16
15
|
"""
|
|
17
16
|
return (next((v for k, v in (kw) if k == (key)), None))
|
|
18
17
|
|
|
@@ -70,9 +69,8 @@ def delete(kw, key):
|
|
|
70
69
|
def merge(kw1, kw2):
|
|
71
70
|
"""Merges `kw2` into `kw1`; `kw2` wins, its entries appended.
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
[('a', 1), ('b', 9), ('c', 3)]
|
|
72
|
+
>>> merge([("a", 1), ("b", 2)], [("b", 9), ("c", 3)])
|
|
73
|
+
[('a', 1), ('b', 9), ('c', 3)]
|
|
76
74
|
"""
|
|
77
75
|
def _gan_fn5(*_gan_args):
|
|
78
76
|
match _gan_args:
|
|
@@ -21,9 +21,8 @@ def last(xs):
|
|
|
21
21
|
def flatten(xs):
|
|
22
22
|
"""Flattens nested lists to any depth.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[1, 2, 3, 4, 5]
|
|
24
|
+
>>> flatten([1, [2, [3, 4]], 5])
|
|
25
|
+
[1, 2, 3, 4, 5]
|
|
27
26
|
"""
|
|
28
27
|
def _gan_fn0(x):
|
|
29
28
|
if _gan_truthy(isinstance(x, list)):
|
|
@@ -76,8 +75,7 @@ def replace_at(xs, index, value):
|
|
|
76
75
|
def update_at(xs, index, f):
|
|
77
76
|
"""Updates the element at `index` by `f`.
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
[1, 20, 3]
|
|
78
|
+
>>> update_at([1, 2, 3], 1, lambda v: v * 10)
|
|
79
|
+
[1, 20, 3]
|
|
82
80
|
"""
|
|
83
81
|
return replace_at(xs, index, f(gandora_std.enum.at(xs, index)))
|
|
@@ -13,9 +13,8 @@ class GanMatchError(Exception):
|
|
|
13
13
|
def get(*_gan_args):
|
|
14
14
|
"""The value for `key`, or `default` (nil unless given) when absent.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
0
|
|
16
|
+
>>> get({"a": 1}, "b", 0)
|
|
17
|
+
0
|
|
19
18
|
"""
|
|
20
19
|
match _gan_args:
|
|
21
20
|
case (m, key, default,):
|
|
@@ -28,9 +27,8 @@ def get(*_gan_args):
|
|
|
28
27
|
def put(m, key, value):
|
|
29
28
|
"""A new map with `key` set to `value`.
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{'a': 1, 'b': 2}
|
|
30
|
+
>>> put({"a": 1}, "b", 2)
|
|
31
|
+
{'a': 1, 'b': 2}
|
|
34
32
|
"""
|
|
35
33
|
return ({**(m), (key): (value)})
|
|
36
34
|
|
|
@@ -73,9 +71,8 @@ def new():
|
|
|
73
71
|
def update(m, key, default, f):
|
|
74
72
|
"""Updates `key` by `f`; uses `default` when the key is absent (Elixir Map.update/4).
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{'a': 11}
|
|
74
|
+
>>> update({"a": 1}, "a", 0, lambda v: v + 10)
|
|
75
|
+
{'a': 11}
|
|
79
76
|
"""
|
|
80
77
|
if _gan_truthy(has_key_p(m, key)):
|
|
81
78
|
return put(m, key, f(get(m, key)))
|
|
@@ -109,8 +106,7 @@ def drop(m, keys):
|
|
|
109
106
|
def filter(m, f):
|
|
110
107
|
"""Keeps entries for which `f` (receiving a `{key, value}` tuple) is truthy.
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
{'b': 5}
|
|
109
|
+
>>> filter({"a": 1, "b": 5}, lambda pair: pair[1] > 2)
|
|
110
|
+
{'b': 5}
|
|
115
111
|
"""
|
|
116
112
|
return ({k: v for k, v in (m).items() if (f)((k, v))})
|
|
@@ -27,9 +27,8 @@ def capitalize(s):
|
|
|
27
27
|
def split(s):
|
|
28
28
|
"""Splits on whitespace runs, dropping empty parts (Elixir semantics).
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
['a', 'b', 'c']
|
|
30
|
+
>>> split(" a b c ")
|
|
31
|
+
['a', 'b', 'c']
|
|
33
32
|
"""
|
|
34
33
|
return s.split()
|
|
35
34
|
|
|
@@ -72,9 +71,8 @@ def length(s):
|
|
|
72
71
|
def slice(s, start, len):
|
|
73
72
|
"""The substring of `len` characters starting at `start` (negative start counts from the end).
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'dora'
|
|
74
|
+
>>> slice("gandora", 3, 4)
|
|
75
|
+
'dora'
|
|
78
76
|
"""
|
|
79
77
|
return ((s)[(start):] [:(len)])
|
|
80
78
|
|
|
@@ -130,9 +128,8 @@ def trim_trailing(s):
|
|
|
130
128
|
def codepoints(s):
|
|
131
129
|
"""The characters as a list of one-character strings.
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
['h', 'é']
|
|
131
|
+
>>> gandora_std.enum.take(codepoints("héllo"), 2)
|
|
132
|
+
['h', 'é']
|
|
136
133
|
"""
|
|
137
134
|
return builtins.list(s)
|
|
138
135
|
|
|
@@ -140,8 +137,7 @@ def codepoints(s):
|
|
|
140
137
|
def match_p(s, regex):
|
|
141
138
|
"""Whether the compiled regex (`~r/.../`) matches anywhere in the string.
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
True
|
|
140
|
+
>>> match_p("gandora-2026", re.compile("\\d+"))
|
|
141
|
+
True
|
|
146
142
|
"""
|
|
147
143
|
return not (_gan_truthy((regex.search(s) is None)))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|