Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decision: support core predicates or just keyword types? #25

Closed
ikitommi opened this issue Aug 2, 2019 · 2 comments
Closed

Decision: support core predicates or just keyword types? #25

ikitommi opened this issue Aug 2, 2019 · 2 comments
Labels
Clojurists Together Sponsored by Clojurists Together Q3 2020 for discussion Discussion is main focus of PR
Milestone

Comments

@ikitommi
Copy link
Member

ikitommi commented Aug 2, 2019

Currently, the malli.core/predicate-registry collects all clojure core predicates and makes valid schemas out of those. This makes it feel like clojure.spec & data-specs:

(require '[malli.core :as m])

(m/validate [:or int? string?] 1)
; => true

This is kinda nice, but all the predicates need to be mapped into types for coercion, so should we default to a (keyword)-type based basic registry, like :int, :string etc instead?

(require '[malli.core :as m])

(m/validate [:or :int :string] 1)
; => true

Currently, the latter can be done easily with custom registry, but the what should be the default?

@ikitommi ikitommi added the for discussion Discussion is main focus of PR label Aug 2, 2019
@ikitommi ikitommi added this to the Initial public version milestone Sep 3, 2019
@nilern
Copy link
Contributor

nilern commented Sep 3, 2019

Keywords should be the default, schemas and types are more than predicates. Also keyword serialization is trivial while predicates are a special case there as well.

@ikitommi
Copy link
Member Author

I also like the type-schemas as a better default. Still, the first alpha should ship with both, as basically every pre-alpha user (us included) is using the predicates already. For 1.0.0, we can revisit the default.

For people, who already care, it's relatively easy just to pick either one, by creating a custom registry and picking just either one:

(def registry 
  (merge 
    (predicate-schemas) ;; drop this
    (type-schemas) ;; or this
    (class-schemas) 
    (comparator-schemas) 
    (base-schemas)))

, the impls being currently:

(defn predicate-schemas []
  (->> [#'any? #'some? #'number? #'integer? #'int? #'pos-int? #'neg-int? #'nat-int? #'pos? #'neg? #'float? #'double?
        #'boolean? #'string? #'ident? #'simple-ident? #'qualified-ident? #'keyword? #'simple-keyword?
        #'qualified-keyword? #'symbol? #'simple-symbol? #'qualified-symbol? #'uuid? #'uri? #?(:clj #'decimal?)
        #'inst? #'seqable? #'indexed? #'map? #'vector? #'list? #'seq? #'char? #'set? #'nil? #'false? #'true?
        #'zero? #?(:clj #'rational?) #'coll? #'empty? #'associative? #'sequential? #?(:clj #'ratio?) #?(:clj #'bytes?)]
       (reduce -register-var {})))

(defn type-schemas []
  {:string (-string-schema)
   :int (-int-schema)
   :double (-double-schema)
   :boolean (-boolean-schema)
   :keyword (-keyword-schema)
   :symbol (-symbol-schema)
   :qualified-keyword (-qualified-keyword-schema)
   :qualified-symbol (-qualified-symbol-schema)
   :uuid (-uuid-schema)})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clojurists Together Sponsored by Clojurists Together Q3 2020 for discussion Discussion is main focus of PR
Projects
None yet
Development

No branches or pull requests

2 participants