We can see the difference between the two if we select some data from them:
(ns playground (:require [clojure.spec :as spec] [clojure.spec.gen :as gen])) (gen/generate (spec/gen (spec/and #{:a :c} #{:b :a :c}))) => :a (gen/sample (spec/gen (spec/and #{:a :c} #{:b :a :c}))) => (:c :a :c :a :a :a :a :a :a :c)
As we can see, spec/and corresponds to single occurrences matching the two predicates #{:a :c} and #{:b :a :c} .
(gen/generate (spec/gen (spec/& #{:a :c} #{:b :a :c}))) => [:c] (gen/sample (spec/gen (spec/& #{:a :c} #{:b :a :c}))) => ([:c] [:a] [:a] [:c] [:c] [:c] [:c] [:a] [:c] [:c])
spec/& , on the other hand, matches what is accepted by predicates as part of a sequence.
source share