Helpers for :idents.

(ns metabase.lib.ident
  (:require
   [metabase.util :as u]))

Generates a new, randomized, globally unique :ident - an opaque string.

(defn random-ident
  []
  (u/generate-nano-id))

Replaces all the values in the given map with [[random-ident]]s, using the original keys.

(defn keyed-idents
  [m]
  (when (seq m)
    (update-vals m (fn [_] (random-ident)))))

Given a seq or a count, generates a [[random-ident]] for each one. Returns a map of indexes to idents.

(defn indexed-idents
  [xs-or-number]
  (let [lhs (if (number? xs-or-number)
              (range xs-or-number)
              (range (count xs-or-number)))]
    (not-empty (zipmap lhs (repeatedly random-ident)))))