Add the ability to retrieve a set of keys from map schemas

This commit is contained in:
Andrey Antukh 2025-05-28 14:40:34 +02:00
parent 3d61924162
commit 5c225a51ce

View File

@ -5,7 +5,7 @@
;; Copyright (c) KALEIDOS INC
(ns app.common.schema
(:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type])
(:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type keys])
#?(:cljs (:require-macros [app.common.schema :refer [ignoring]]))
(:require
[app.common.data :as d]
@ -118,6 +118,21 @@
[& transformers]
(apply mt/transformer transformers))
(defn entries
"Get map entires of a map schema"
[schema]
(m/entries schema default-options))
(def ^:private xf:map-key
(map key))
(defn keys
"Given a map schema, return all keys as set"
[schema]
(->> (entries schema)
(into #{} xf:map-key)))
;; (defn key-transformer
;; [& {:as opts}]
;; (mt/key-transformer opts))