<commit_before>(ns re-frame.core
  (:require
    [re-frame.handlers   :as handlers]
    [re-frame.subs       :as subs]
    [re-frame.middleware :as middleware]))


;; --  API  -------

(def register-handler handlers/register)
(def dispatch         handlers/dispatch)
(def dispatch-sync    handlers/dispatch-sync)

(def register-sub  subs/register)
(def subscribe     subs/subscribe)



(def pure        middleware/pure)
(def debug       middleware/debug)
(def undoable    middleware/undoable)
(def path        middleware/path)
(def validate    middleware/validate)
(def trim-v      middleware/trim-v)
; (def log-events  middleware/log-events)



;; --  Convienience  -------

;; virtually ever handler will be pure, make it easy
(defn register-pure-handler
  ([id handler]
    (register-handler id pure handler))
  ([id middleware handler]
    (register-handler id [pure middleware] handler)))<commit_msg>Add new API    - a noop middleware    - a comp-middleware<commit_after>(ns re-frame.core
  (:require
    [re-frame.handlers   :as handlers]
    [re-frame.subs       :as subs]
    [re-frame.middleware :as middleware]))


;; --  API  -------

(def register-handler handlers/register)
(def dispatch         handlers/dispatch)
(def dispatch-sync    handlers/dispatch-sync)

(def register-sub  subs/register)
(def subscribe     subs/subscribe)



(def noop        middleware/noop)
(def pure        middleware/pure)
(def debug       middleware/debug)
(def undoable    middleware/undoable)
(def path        middleware/path)
(def validate    middleware/validate)
(def trim-v      middleware/trim-v)
; (def log-events  middleware/log-events)



;; --  Convienience  -------

;; virtually ever handler will be pure, make it easy
(defn register-pure-handler
  ([id handler]
    (register-handler id pure handler))
  ([id middleware handler]
    (register-handler id [pure middleware] handler)))


(defn comp-middleware
  "Given a vector of middleware, filter out any nils, and use comp to compose.
  v can  be vectors of vectors and will be flattended before use.
  For convienience, if v turns out to already be a function, just return it."
  [v]
  (if (ifn? v)     ;; noop if v is a fucntion
    v
    (do
      (assert  (or (vector? v) (list v))
               (str "re-frame:  compose expects a vector, got: " v))
      (let [v (remove nil? (flatten v))]
        (cond
          (empty? v)       noop
          (= 1 (count v))  (first v)
          :else            (apply comp v))))))

{'fraction_non_alphanumeric': 0.12082158679017317, 'fraction_numerical': 0.0004027386226339106, 'mean_word_length': 2.5792507204610953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '477325', 'n_tokens_mistral': 815, 'n_tokens_neox': 778, 'n_words': 246}