Skip to content

Commit 6945a04

Browse files
authored
Return List and Vector when slicing List and Vector (#96)
* Return List and Vector when slicing List and Vector * Test
1 parent cf41030 commit 6945a04

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

basilisp/lang/list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __eq__(self, other):
2323
return self._inner == other
2424

2525
def __getitem__(self, item):
26+
if isinstance(item, slice):
27+
return List(self._inner[item])
2628
return self._inner[item]
2729

2830
def __hash__(self):

basilisp/lang/vector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __eq__(self, other):
2323
return self._inner == other
2424

2525
def __getitem__(self, item):
26+
if isinstance(item, slice):
27+
return Vector(self._inner[item])
2628
return self._inner[item]
2729

2830
def __hash__(self):

tests/list_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def test_list_seq_interface():
1616
assert issubclass(llist.List, lseq.Seq)
1717

1818

19+
def test_list_slice():
20+
assert isinstance(llist.l(1, 2, 3)[1:], llist.List)
21+
22+
1923
def test_list_conj():
2024
meta = lmap.m(tag="async")
2125
l1 = llist.l(keyword("kw1"), meta=meta)

tests/vector_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def test_vector_seqable_interface():
1616
assert issubclass(vector.Vector, lseq.Seqable)
1717

1818

19+
def test_vector_slice():
20+
assert isinstance(vector.v(1, 2, 3)[1:], vector.Vector)
21+
22+
1923
def test_vector_conj():
2024
meta = lmap.m(tag="async")
2125
v1 = vector.v(keyword("kw1"), meta=meta)

0 commit comments

Comments
 (0)