Skip to content

Commit d9fc6d4

Browse files
authored
Merge pull request #2 from purescript-python/revert-1-fix-list-to-tuple
Revert "Fix list to tuple"
2 parents 35dbeee + a6059db commit d9fc6d4

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

Diff for: python-ffi/Data/Array.py

+17-24
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
def _rangeImpl(start):
77
def ap(end):
88
step = 1 if start <= end else -1
9-
return tuple(_buitins["range"](start, end + step, step))
9+
return list(_buitins["range"](start, end + step, step))
1010

1111
return ap
1212

1313

1414
globals()["range"] = _rangeImpl
1515

1616

17-
replicate = lambda count: lambda value: tuple([value for _ in _buitins["range"](count)])
17+
replicate = lambda count: lambda value: [value for _ in _buitins["range"](count)]
1818

1919

2020
def _mkFromFoldableImpl():
@@ -37,7 +37,7 @@ def listToArray(lst):
3737
while xs is not None:
3838
result.append(xs.head)
3939
xs = xs.tail
40-
return tuple(result)
40+
return result
4141

4242
def result(foldr):
4343
def ap(xs):
@@ -47,17 +47,14 @@ def ap(xs):
4747

4848
return result
4949

50-
# TODO: discuss performance consideration with alternative implementation
51-
# at least should we use 2-tuple instead of class?
52-
# current implementation is aiming to mimic JS implementation as much as possible
53-
# same problem in NonEmpty.Internal.py
50+
5451
fromFoldableImpl = _mkFromFoldableImpl()
5552

5653
length = lambda xs: len(xs)
5754

58-
cons = lambda e: lambda l: (e, *l)
55+
cons = lambda e: lambda l: [e, *l]
5956

60-
snoc = lambda xs: lambda x: (*xs, x)
57+
snoc = lambda xs: lambda x: [*xs, x]
6158

6259

6360
def unconsImpl(empty):
@@ -114,11 +111,9 @@ def findLastIndexImpl(just):
114111
def _insertAtImpl(just, nothing, i, a, l):
115112
if i < 0 or i > len(l):
116113
return nothing
117-
# TODO: discuss performance consideration with alternative implementation
118-
# (*l[i-1], a, *l[i:])
119114
ll = list(l)
120115
ll.insert(i, a)
121-
return just(tuple(ll))
116+
return just(ll)
122117

123118

124119
_insertAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _insertAtImpl(
@@ -142,24 +137,24 @@ def _updateAtImpl(just, nothing, i, a, l):
142137
return nothing
143138
ll = list(l)
144139
ll[i] = a
145-
return just(tuple(ll))
140+
return just(ll)
146141

147142

148143
_updateAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _updateAtImpl(
149144
just, nothing, i, a, l
150145
)
151146

152-
reverse = lambda xs: tuple(reversed(xs))
147+
reverse = lambda xs: list(reversed(xs))
153148

154149

155150
def concat(xss):
156151
result = []
157152
for x in xss:
158153
result.extend(x)
159-
return tuple(result)
154+
return result
160155

161156

162-
filter = lambda f: lambda xs: tuple(_buitins["filter"](f, xs))
157+
filter = lambda f: lambda xs: list(_buitins["filter"](f, xs))
163158

164159

165160
def partition(f):
@@ -171,22 +166,20 @@ def result(xs):
171166
yes.append(x)
172167
else:
173168
no.append(x)
174-
return {"yes": tuple(yes), "no": tuple(no)}
169+
return {"yes": yes, "no": no}
175170

176171
return result
177172

178173

179-
sortImpl = lambda f: lambda xs: tuple(
180-
sorted(xs, key=functools.cmp_to_key(lambda a, b: f(a)(b)))
174+
sortImpl = lambda f: lambda xs: sorted(
175+
xs, key=functools.cmp_to_key(lambda a, b: f(a)(b))
181176
)
182177

183178
slice = lambda s: lambda e: lambda xs: xs[s:e]
184179

185-
take = lambda n: lambda xs: xs[: max(n, 0)]
186-
drop = lambda n: lambda xs: xs[max(n, 0) :]
180+
take = lambda n: lambda xs: xs[:max(n, 0)]
181+
drop = lambda n: lambda xs: xs[max(n, 0):]
187182

188-
zipWith = lambda f: lambda xs: lambda ys: tuple(
189-
map(lambda t: f(t[0])(t[1]), zip(xs, ys))
190-
)
183+
zipWith = lambda f: lambda xs: lambda ys: list(map(lambda t: f(t[0])(t[1]), zip(xs, ys)))
191184

192185
unsafeIndexImpl = lambda xs: lambda n: xs[n]

Diff for: python-ffi/Data/Array/NonEmpty/Internal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def listToArray(lst):
4242
while xs is not emptyList:
4343
arr.append(xs.head)
4444
xs = xs.tail
45-
return tuple(arr)
45+
return arr
4646

4747
def kernel(apply, map_, f):
4848
def buildFrom(x, ys):

0 commit comments

Comments
 (0)