aboutsummaryrefslogtreecommitdiff
path: root/src/cashflow/utils.clj
blob: 227a2e751a1822a2ce64be69cd8d12fa83fe24c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(ns cashflow.utils)

(defn- n*string [n string]
  (when (string? string)
    (->> (for [_ (range n)] string)
         (apply str))))

(defn string-min-length
  "Returns string `s` when length of string is `min-length`, otherwise fills string up with a `filler` character, either before `s` if `position` :before or after `s` if `position` is :after."
  [s min-length filler position]
  (when (string? s)
    (let [filler-string (-> (- min-length (.length s))
                            (n*string filler))]
      (cond
        (= position :before)
        (str filler-string s)

        (= position :after)
        (str s filler-string)

        :else
        s))))