Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Declined
-
Affects Version/s: Release 1.3
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:OSX Lion
Description
contains? returns the wrong result for the last item in a vector:
user> (map #(contains? [1 2 3 4] %) [1 2 3 4])
(true true true false)
This is a (common) misusing of contains?. Perhaps it would have been better if contains? had been named contains-key?, but that ship has sailed.
A vector of length 4 has four keys (indexes): 0, 1, 2, 3, which is why your example is returning (true true true false).
To get the behavior your are expecting from contains?, use some:
user> (map #(some #{%} [1 2 3 4]) [1 2 3 4]) (1 2 3 4) ; all of which are truthyIf you prefer booleans, you could do something like this:
user> (map (comp boolean #(some #{%} [1 2 3 4])) [1 2 3 4]) (true true true true)user> (map #(some #{%} [1 2 3 4]) [1 2 3 4]) (1 2 3 4) ; all of which are truthyuser> (map (comp boolean #(some #{%} [1 2 3 4])) [1 2 3 4]) (true true true true)