<commit_before>(ns runbld.util.data
  (:require [clojure.walk]))

;; http://dev.clojure.org/jira/browse/CLJ-1468
(defn deep-merge
  "Like merge, but merges maps recursively."
  {:added "1.7"}
  [& maps]
  (if (every? map? maps)
    (apply merge-with deep-merge maps)
    (last maps)))

(defn deep-merge-with
  "Like merge-with, but merges maps recursively, applying the given fn
  only when there's a non-map at a particular level."
  {:added "1.7"}
  [f & maps]
  (apply
   (fn m [& maps]
     (if (every? map? maps)
       (apply merge-with m maps)
       (apply f maps)))
   maps))
<commit_msg>Add decimal helpers<commit_after>(ns runbld.util.data
  (:refer-clojure :exclude [bigdec])
  (:require [clojure.walk]))

;; http://dev.clojure.org/jira/browse/CLJ-1468
(defn deep-merge
  "Like merge, but merges maps recursively."
  {:added "1.7"}
  [& maps]
  (if (every? map? maps)
    (apply merge-with deep-merge maps)
    (last maps)))

(defn deep-merge-with
  "Like merge-with, but merges maps recursively, applying the given fn
  only when there's a non-map at a particular level."
  {:added "1.7"}
  [f & maps]
  (apply
   (fn m [& maps]
     (if (every? map? maps)
       (apply merge-with m maps)
       (apply f maps)))
   maps))

(defn safe-div
  ([n m]
   (if (and m (pos? m))
     (/ n m)
     0)))

(defn bigdec
  "Set f to n places after the decimal."
  ([f]
   (clojure.core/bigdec f))
  ([f n]
   (when f
     (-> (clojure.core/bigdec f)
         (.setScale n BigDecimal/ROUND_HALF_UP)))))
{'fraction_non_alphanumeric': 0.15768463073852296, 'fraction_numerical': 0.011310711909514305, 'mean_word_length': 2.8075949367088606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2066658', 'n_tokens_mistral': 597, 'n_tokens_neox': 580, 'n_words': 173}