Equality defined between builtin collections respect partitions #558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR corrects the equality operators between builtin collection types to respect equality partitions. Equality partitions are segments of different collections within which collections can be considered equal and between which collections cannot be considered equal. The three equality partitions are: sequential types (vectors, seqs), maps, and sets.
Several other small changes were made in support of that goal:
Map
types now properly support the full PythonMapping
protocol.Map.__iter__
now acts like a standard PythonMapping
type, returning an iterable of keys. Formerly, it was an iterable ofMapEntry
types, which was occasionally convenient, but definitely un-idiomatic in Python. This change doesn't really affect Basilisp code though, since Basilisp always calls.seq()
on maps to iterate over entries..iteritems()
,.iterkeys()
, and.itervalues()
methods which simply forwarded to the basepyrsistent.PMap
implementation.Mapping.items()
,.keys()
, and.values()
are now supported. All cases relying on the former__iter__
implementation have generally been updated to use.items()
(though a few cases were updated to use.seq()
).ISeq
types andIPersistentVector
have been annotated with the marker interfaceISequential
which is attached to all sequential types in that equality partition.IPersistentVector
types are no longer consideredMapping
types, though they are still consideredIAssociative
. It never really made sense to consider themMapping
types and it was generally inconvenient since it is not useful to consider vectors as maps in most cases.Vector.rseq()
implementation since it was undoubtedly no more efficient than Python'sreversed
using the PythonSequence
protocol.Two small fixes unrelated to the main changes were also included because I was already in the code:
basilisp.core/rest
now never returnsnil
. Instead, it returns the empty seq in any case it would formerly returnnil
.References:
Fixes #556