Skip to content

Commit 296ab78

Browse files
authored
Builtin collection types should always evaluate as True (#566)
* Builtin collection types should always evaluate as True * Fix next definition * Change the log
1 parent 955d0bf commit 296ab78

File tree

12 files changed

+32
-5
lines changed

12 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
* Fixed a bug where `deftype` forms could not be created interfaces declared not at the top-level of a code block in a namespace (#376)
3434
* Fixed multiple bugs relating to symbol resolution of `import`ed symbols in various contexts (#544)
3535
* Fixed a bug where the `=` function did not respect the equality partition for various builtin collection types (#556)
36+
* Fixed a bug where collection types could evaluate as boolean `false` (#566)
3637

3738
## [v0.1.dev13] - 2020-03-16
3839
### Added

src/basilisp/lang/list.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def __init__(self, wrapped: "PList[T]", meta=None) -> None:
2222
self._inner = wrapped
2323
self._meta = meta
2424

25+
def __bool__(self):
26+
return True
27+
2528
def __getitem__(self, item):
2629
if isinstance(item, slice):
2730
return List(self._inner[item])

src/basilisp/lang/map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def __init__(
3939
self._inner = _Map(members)
4040
self._meta = meta
4141

42+
def __bool__(self):
43+
return True
44+
4245
def __call__(self, key, default=None):
4346
return self._inner.get(key, default)
4447

src/basilisp/lang/runtime.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,7 @@ def nthrest(coll, i: int):
900900
def next_(o) -> Optional[ISeq]:
901901
"""Calls rest on o. If o returns an empty sequence or None, returns None.
902902
Otherwise, returns the elements after the first in o."""
903-
s = rest(o)
904-
if not s:
905-
return None
906-
return s
903+
return to_seq(rest(o))
907904

908905

909906
def nthnext(coll, i: int) -> Optional[ISeq]:

src/basilisp/lang/seq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __repr__(self):
1111
return "()"
1212

1313
def __bool__(self):
14-
return False
14+
return True
1515

1616
@property
1717
def meta(self) -> Optional[IPersistentMap]:

src/basilisp/lang/set.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def __init__(self, members: Optional[Iterable[T]], meta=None) -> None:
2828
self._inner = _Map((m, m) for m in (members or ()))
2929
self._meta = meta
3030

31+
def __bool__(self):
32+
return True
33+
3134
def __call__(self, key, default=None):
3235
if key in self:
3336
return key

src/basilisp/lang/vector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __init__(
3030
self._inner = wrapped
3131
self._meta = meta
3232

33+
def __bool__(self):
34+
return True
35+
3336
def __contains__(self, item):
3437
return item in self._inner
3538

tests/basilisp/list_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_list_slice():
4040
assert isinstance(llist.l(1, 2, 3)[1:], llist.List)
4141

4242

43+
def test_list_bool():
44+
assert True is bool(llist.List.empty())
45+
46+
4347
def test_list_cons():
4448
meta = lmap.m(tag="async")
4549
l1 = llist.l(keyword("kw1"), meta=meta)

tests/basilisp/map_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def test_assoc():
5353
assert lmap.map({"a": 3, "b": 2}) == m1.assoc("b", 2)
5454

5555

56+
def test_map_bool():
57+
assert True is bool(lmap.Map.empty())
58+
59+
5660
def test_map_as_function():
5761
assert None is lmap.m()(1)
5862
assert None is lmap.m()("abc")

tests/basilisp/seq_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_empty_sequence():
7878
assert empty.rest == empty
7979
assert llist.l(1) == empty.cons(1)
8080
assert lseq.EMPTY is empty
81+
assert True is bool(lseq.sequence([]))
8182

8283

8384
def test_sequence():

0 commit comments

Comments
 (0)