<commit_before>(ns ^:no-doc structural-typing.guts.shapes.pred
  (:require [such.readable :as readable]
            [structural-typing.guts.frob :as frob]
            [structural-typing.pred-writing.shapes.expred :as expred]
            [structural-typing.defaults :as defaults]
))

;; TODO: make readable have the "ensure-meta" behavior)


(defn gm [f k default] (get (meta f) k default))
(defn vm [f k v] (vary-meta f assoc k v))
(defn ensure-meta [f k v] (if (contains? (meta f) k) f (vm f k v)))


(defn get-predicate-string [f] (readable/fn-string f))
(defn get-predicate [f]        (gm f ::original-predicate f))
(defn get-explainer [f]        (gm f ::predicate-explainer defaults/default-predicate-explainer))


(defn stash-defaults [f]
  (-> f
      (ensure-meta ::original-predicate f)
      (readable/rename (readable/fn-string f))))

(defn replace-predicate-string [f name] (readable/rename f name))
(defn replace-explainer [f explainer] (vm f ::predicate-explainer explainer))
  
(defn show-as 
  "Associate the given `name` string with the predicate for use when predicate failures
   are explained.
     
         (->> (partial >= 3) (show-as \"less than 3\"))
"
  [name predicate]
  (when (fn? name) (frob/boom! "First arg is a function. You probably got your args reversed."))
  (when-not (string? name) (frob/boom! "First arg must be a string: %s %s" name predicate))
  (-> predicate
      stash-defaults
      (replace-predicate-string name)))

(defn explain-with
  "After the `predicate` fails, the failure will need to be explained. Arrange for
   the `explainer` function to be called with the [[oopsie]] that results from the
   failure."
  [explainer predicate]
  (-> predicate
      stash-defaults
      (replace-explainer explainer)))




(def ^:private lifted-mark ::lifted)
(defn mark-as-lifted [pred]
  (vary-meta pred assoc lifted-mark true))
(defn already-lifted? [pred]
  (lifted-mark (meta pred)))
<commit_msg>`explain-with` docstring didn't have an example<commit_after>(ns ^:no-doc structural-typing.guts.shapes.pred
  (:require [such.readable :as readable]
            [structural-typing.guts.frob :as frob]
            [structural-typing.pred-writing.shapes.expred :as expred]
            [structural-typing.defaults :as defaults]
))

;; TODO: make readable have the "ensure-meta" behavior)


(defn gm [f k default] (get (meta f) k default))
(defn vm [f k v] (vary-meta f assoc k v))
(defn ensure-meta [f k v] (if (contains? (meta f) k) f (vm f k v)))


(defn get-predicate-string [f] (readable/fn-string f))
(defn get-predicate [f]        (gm f ::original-predicate f))
(defn get-explainer [f]        (gm f ::predicate-explainer defaults/default-predicate-explainer))


(defn stash-defaults [f]
  (-> f
      (ensure-meta ::original-predicate f)
      (readable/rename (readable/fn-string f))))

(defn replace-predicate-string [f name] (readable/rename f name))
(defn replace-explainer [f explainer] (vm f ::predicate-explainer explainer))
  
(defn show-as 
  "Associate the given `name` string with the predicate for use when predicate failures
   are explained.
     
         (->> (partial >= 3) (show-as \"less than 3\"))
"
  [name predicate]
  (when (fn? name) (frob/boom! "First arg is a function. You probably got your args reversed."))
  (when-not (string? name) (frob/boom! "First arg must be a string: %s %s" name predicate))
  (-> predicate
      stash-defaults
      (replace-predicate-string name)))

(defn explain-with
  "After the `predicate` fails, the failure will need to be explained. Arrange for
   the `explainer` function to be called with the [[oopsie]] that results from the
   failure.
   
        (explain-with \"too small\" #(< (count %) 54))
"
  [explainer predicate]
  (-> predicate
      stash-defaults
      (replace-explainer explainer)))




(def ^:private lifted-mark ::lifted)
(defn mark-as-lifted [pred]
  (vary-meta pred assoc lifted-mark true))
(defn already-lifted? [pred]
  (lifted-mark (meta pred)))

{'fraction_non_alphanumeric': 0.13775766716943189, 'fraction_numerical': 0.0015082956259426848, 'mean_word_length': 3.3533916849015317, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2878569', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1327, 'n_words': 436}