mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
17 lines
592 B
Python
17 lines
592 B
Python
class Array(list):
|
|
def dedup(self, same_bucket=None):
|
|
if same_bucket is None:
|
|
return Array(list(set(self)))
|
|
else:
|
|
removes = []
|
|
for (lhs, rhs) in zip(self, self[1:]):
|
|
if same_bucket(lhs, rhs):
|
|
removes.append(lhs)
|
|
for remove in removes:
|
|
self.remove(remove)
|
|
return self
|
|
def push(self, value):
|
|
self.append(value)
|
|
return self
|
|
def partition(self, f):
|
|
return Array(list(filter(f, self))), Array(list(filter(lambda x: not f(x), self)))
|