Skip to content

Commit ec5c5a4

Browse files
authored
Keyword fn should test for membership in sets (#763)
Hi, could you please review patch to have keyword fn test for membership in sets. It fixes #762. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent fc4fba8 commit ec5c5a4

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313
* Fix issue with `(count nil)` throwing an exception (#759)
14+
* Fix issue with keyword fn not testing for test membership in sets (#762)
1415

1516
## [v0.1.0b0]
1617
### Added

src/basilisp/lang/keyword.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import threading
22
from functools import total_ordering
3-
from typing import Iterable, Optional
3+
from typing import Iterable, Optional, Union
44

55
from basilisp.lang import map as lmap
6-
from basilisp.lang.interfaces import IAssociative, ILispObject, IPersistentMap
6+
from basilisp.lang.interfaces import (
7+
IAssociative,
8+
ILispObject,
9+
IPersistentMap,
10+
IPersistentSet,
11+
)
712

813
_LOCK = threading.Lock()
914
_INTERN: IPersistentMap[int, "Keyword"] = lmap.PersistentMap.empty()
@@ -53,7 +58,9 @@ def __lt__(self, other):
5358
return False
5459
return self._ns < other._ns or self._name < other._name
5560

56-
def __call__(self, m: IAssociative, default=None):
61+
def __call__(self, m: Union[IAssociative, IPersistentSet], default=None):
62+
if isinstance(m, IPersistentSet):
63+
return self if self in m else default
5764
try:
5865
return m.val_at(self, default)
5966
except AttributeError:

tests/basilisp/keyword_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from basilisp.lang import map as lmap
6+
from basilisp.lang import set as lset
67
from basilisp.lang.keyword import Keyword, complete, keyword
78

89

@@ -46,6 +47,10 @@ def test_keyword_as_function():
4647
assert "hi" == kw(lmap.map({kw: "hi"}))
4748
assert None is kw(lmap.map({"hi": kw}))
4849

50+
assert kw == kw(lset.s(kw))
51+
assert None is kw(lset.s(1))
52+
assert "hi" is kw(lset.s(1), default="hi")
53+
4954

5055
@pytest.mark.parametrize(
5156
"o",

0 commit comments

Comments
 (0)