Skip to content

clojure.set/subset?

View this page on ClojureDocs

Type: function Added: Clojure 1.2 Examples: 3 Runnable: 0
([set1 set2])

Is set1 a subset of set2?

Examples

by dakrone on . May have evaluation errors.
by jafingerhut on . May have evaluation errors.
by wxnn08 on . May have evaluation errors.

Note by arkdrag

Do note that this will only work as expected for sets. subset? uses contains? in it's implementation. The functionality in contains? for vectors can be slightly unintuitive at first, and causes functions like this to perform in completely unexpected ways when using vectors instead of sets. For example,

user> (clojure.set/subset?  [0 1] [2 3])
true
user> (clojure.set/subset?  [2 3] [2 3])
false

It is slightly more intuitive with maps, as it checks whether every item in the first collection is a key in the map passed in as the 2nd parameter, but still is probably a bit confusing to someone reading your code.

user> (clojure.set/subset? '(7 8)  {8 1 7 3})
true
user> (clojure.set/subset? '(9 10)  {8 1 7 3})
false

Long story short, if you're using functions from the clojure.set namespace, make sure you're passing in sets.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.