Couldn't satisfy such-that predicate after 100 tries {} when trying to generate samples from spec definition

Given the following spec definitions

(ns spec-playground.spec.standard
  (:require [clojure.spec.alpha :as s]))

(defn- state-length [str]
  (= 2 (count str)))
(s/def ::field-one string?)
(s/def ::field-two string?)
(s/def ::person (s/keys :req-un [::field-one ::field-two]))
(s/def ::city string?)
(s/def ::state (s/and string? #(state-length %)))
(s/def ::zip string?)
(s/def ::street string?)

(s/def ::address (s/keys :req-un [::street ::city ::state ::zip]))
(s/def ::addresses (s/coll-of ::address :distinct true :into [] :kind vector? :min-count 1 :max-count 5))
(s/def ::complete-person (s/keys :req-un [::person]
                                 :opt-un [::addresses]))

(gen/sample (s/gen ::standard/addresses))

throws an error in the repl

Couldn’t satisfy such-that predicate after 100 tries {}

I did find this stack overflow post, but I’m not sure how to apply the given solution since I am not attempting to spec an entire function.

I would appreciate any insight into how to deal with this type of problem.

Here’s one way to do it:

(s/def ::state (s/with-gen
                 (s/and string? #(state-length %))
                 (fn []
                   (gen/fmap #(subs % 0 2)
                             (s/gen (s/and string? #(>= (count %) 2)))))))

Note that those numbers 2 in there are the length hard-coded in state-length, so it might make sense to extract it as a constant.

Thank you.