contains? should throw exception on non-keyed collections


The contains? function, given a collection which is not an associative (Map, Set, String, array), returns false instead of throwing an exception.

This is a subject of confusion when people call contains? on sequential collections like lists, and on associative collections which do not implement the Associative interface.

Other predicates, such as even?, throw an exception when passed arguments of an invalid type.




Aaron Bedra
August 15, 2012, 6:31 PM

This seems to be working properly, but what about vectors?

Andy Fingerhut
August 15, 2012, 6:40 PM

The doc string for contains? covers the vector and Java array case explicitly. I'm not saying that this behavior shouldn't change, but at least it is well documented what it currently does in these cases.

Aaron Bedra
August 15, 2012, 8:03 PM

Agreed. I just want to make sure that we are still ok with this functionality given that things are changing. Are there others (Stuart) that want to chime in here and make the intentions clear? If this is good then I would consider this screened and ready.

Stuart Sierra
August 15, 2012, 8:40 PM

Vector is Associative, so supporting contains? is valid even if it does not do what people might expect:

All I'm trying to change here is have contains? throw an exception if the argument is not Associative. The current behavior (returning false) was hiding a bug in my code.

I do not consider this a breaking change. I believe the docstring of contains? leaves room for this interpretation, but Rich will have the final say.

Aaron Bedra
August 15, 2012, 8:42 PM

Perfect. I just wanted to make sure that this was intended.


Stuart Sierra


Stuart Sierra






Code and Test

Fix versions