From a6059dbc9b760b86313349b7cb0ffcf420bf27cc Mon Sep 17 00:00:00 2001 From: Taine Zhao Date: Sun, 28 Jun 2020 23:02:00 +0900 Subject: [PATCH] Revert "Fix list to tuple" --- python-ffi/Data/Array.py | 41 +++++++++------------- python-ffi/Data/Array/NonEmpty/Internal.py | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/python-ffi/Data/Array.py b/python-ffi/Data/Array.py index e3f03e2..a2bf1c7 100644 --- a/python-ffi/Data/Array.py +++ b/python-ffi/Data/Array.py @@ -6,7 +6,7 @@ def _rangeImpl(start): def ap(end): step = 1 if start <= end else -1 - return tuple(_buitins["range"](start, end + step, step)) + return list(_buitins["range"](start, end + step, step)) return ap @@ -14,7 +14,7 @@ def ap(end): globals()["range"] = _rangeImpl -replicate = lambda count: lambda value: tuple([value for _ in _buitins["range"](count)]) +replicate = lambda count: lambda value: [value for _ in _buitins["range"](count)] def _mkFromFoldableImpl(): @@ -37,7 +37,7 @@ def listToArray(lst): while xs is not None: result.append(xs.head) xs = xs.tail - return tuple(result) + return result def result(foldr): def ap(xs): @@ -47,17 +47,14 @@ def ap(xs): return result -# TODO: discuss performance consideration with alternative implementation -# at least should we use 2-tuple instead of class? -# current implementation is aiming to mimic JS implementation as much as possible -# same problem in NonEmpty.Internal.py + fromFoldableImpl = _mkFromFoldableImpl() length = lambda xs: len(xs) -cons = lambda e: lambda l: (e, *l) +cons = lambda e: lambda l: [e, *l] -snoc = lambda xs: lambda x: (*xs, x) +snoc = lambda xs: lambda x: [*xs, x] def unconsImpl(empty): @@ -114,11 +111,9 @@ def findLastIndexImpl(just): def _insertAtImpl(just, nothing, i, a, l): if i < 0 or i > len(l): return nothing - # TODO: discuss performance consideration with alternative implementation - # (*l[i-1], a, *l[i:]) ll = list(l) ll.insert(i, a) - return just(tuple(ll)) + return just(ll) _insertAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _insertAtImpl( @@ -142,24 +137,24 @@ def _updateAtImpl(just, nothing, i, a, l): return nothing ll = list(l) ll[i] = a - return just(tuple(ll)) + return just(ll) _updateAt = lambda just: lambda nothing: lambda i: lambda a: lambda l: _updateAtImpl( just, nothing, i, a, l ) -reverse = lambda xs: tuple(reversed(xs)) +reverse = lambda xs: list(reversed(xs)) def concat(xss): result = [] for x in xss: result.extend(x) - return tuple(result) + return result -filter = lambda f: lambda xs: tuple(_buitins["filter"](f, xs)) +filter = lambda f: lambda xs: list(_buitins["filter"](f, xs)) def partition(f): @@ -171,22 +166,20 @@ def result(xs): yes.append(x) else: no.append(x) - return {"yes": tuple(yes), "no": tuple(no)} + return {"yes": yes, "no": no} return result -sortImpl = lambda f: lambda xs: tuple( - sorted(xs, key=functools.cmp_to_key(lambda a, b: f(a)(b))) +sortImpl = lambda f: lambda xs: sorted( + xs, key=functools.cmp_to_key(lambda a, b: f(a)(b)) ) slice = lambda s: lambda e: lambda xs: xs[s:e] -take = lambda n: lambda xs: xs[: max(n, 0)] -drop = lambda n: lambda xs: xs[max(n, 0) :] +take = lambda n: lambda xs: xs[:max(n, 0)] +drop = lambda n: lambda xs: xs[max(n, 0):] -zipWith = lambda f: lambda xs: lambda ys: tuple( - map(lambda t: f(t[0])(t[1]), zip(xs, ys)) -) +zipWith = lambda f: lambda xs: lambda ys: list(map(lambda t: f(t[0])(t[1]), zip(xs, ys))) unsafeIndexImpl = lambda xs: lambda n: xs[n] diff --git a/python-ffi/Data/Array/NonEmpty/Internal.py b/python-ffi/Data/Array/NonEmpty/Internal.py index 0566c7a..2644f5b 100644 --- a/python-ffi/Data/Array/NonEmpty/Internal.py +++ b/python-ffi/Data/Array/NonEmpty/Internal.py @@ -42,7 +42,7 @@ def listToArray(lst): while xs is not emptyList: arr.append(xs.head) xs = xs.tail - return tuple(arr) + return arr def kernel(apply, map_, f): def buildFrom(x, ys):