<commit_before>(ns onyx.static.util)

(defn index-of [coll element]
  (ffirst 
   (filter (fn [[index elem]] (= elem element)) 
           (map list (range) coll))))

#?(:cljs
   (defn munge-fn-name [kw]
     (str (munge-str (str (namespace kw)))
          "."
          (munge-str (str (name kw))))))

#?(:cljs
   (defn resolve-dynamic [kw]
           (js/eval (munge-fn-name kw))))

(defn kw->fn [kw]
  #?(:clj
     (try
       (let [user-ns (symbol (namespace kw))
             user-fn (symbol (name kw))]
         (or (ns-resolve user-ns user-fn)
             (throw (Exception.))))
       (catch Throwable e
         (throw (ex-info (str "Could not resolve symbol on the classpath, did you require the file that contains the symbol " kw "?") {:kw kw})))))
  #?(:cljs (resolve-dynamic kw)))

(defn exception? [e]
  #?(:clj (instance? java.lang.Throwable e))
  #?(:cljs (instance? js/Error e)))

(defn now []
  #?(:clj (System/currentTimeMillis))
  #?(:cljs (.now js/Date)))

#?(:clj
   (defn deserializable-exception [^Throwable throwable more-context]
     (let [{:keys [data trace]} (Throwable->map throwable)
           data (merge (assoc data :original-exception (keyword (.getName (.getClass throwable))))
                       more-context)]
       ;; First element may either be a StackTraceElement or a vector
       ;; of 4 elements, those of which construct a STE.
       (if (sequential? (first trace))
         (let [ste (map #(StackTraceElement.
                          (str (nth % 0))
                          (str (nth % 1))
                          (nth % 2)
                          (nth % 3))
                        trace)]
           (doto ^Throwable (ex-info (.getMessage throwable) data)<commit_msg>Only set the original exception once, thus making deserializable-exception idempontent.<commit_after>(ns onyx.static.util)

(defn index-of [coll element]
  (ffirst 
   (filter (fn [[index elem]] (= elem element)) 
           (map list (range) coll))))

#?(:cljs
   (defn munge-fn-name [kw]
     (str (munge-str (str (namespace kw)))
          "."
          (munge-str (str (name kw))))))

#?(:cljs
   (defn resolve-dynamic [kw]
           (js/eval (munge-fn-name kw))))

(defn kw->fn [kw]
  #?(:clj
     (try
       (let [user-ns (symbol (namespace kw))
             user-fn (symbol (name kw))]
         (or (ns-resolve user-ns user-fn)
             (throw (Exception.))))
       (catch Throwable e
         (throw (ex-info (str "Could not resolve symbol on the classpath, did you require the file that contains the symbol " kw "?") {:kw kw})))))
  #?(:cljs (resolve-dynamic kw)))

(defn exception? [e]
  #?(:clj (instance? java.lang.Throwable e))
  #?(:cljs (instance? js/Error e)))

(defn now []
  #?(:clj (System/currentTimeMillis))
  #?(:cljs (.now js/Date)))

#?(:clj
   (defn deserializable-exception [^Throwable throwable more-context]
     (let [{:keys [data trace]} (Throwable->map throwable)
           this-ex-type (keyword (.getName (.getClass throwable)))
           data (-> data
                    (assoc :original-exception (:original-exception data this-ex-type))
                    (merge more-context))]
       ;; First element may either be a StackTraceElement or a vector
       ;; of 4 elements, those of which construct a STE.
       (if (sequential? (first trace))
         (let [ste (map #(StackTraceElement.
                          (str (nth % 0))
                          (str (nth % 1))
                          (nth % 2)
                          (nth % 3))
                        trace)]
           (doto ^Throwable (ex-info (.getMessage throwable) data)
{'fraction_non_alphanumeric': 0.15212589729431253, 'fraction_numerical': 0.0027609055770292656, 'mean_word_length': 2.0419815281276237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1328680', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1125, 'n_words': 350}