Coder Social home page Coder Social logo

Comments (5)

ikitommi avatar ikitommi commented on June 11, 2024

You can already add Class -> Schema via registry:

(m/validate [:tuple String Long]
            ["123" 123]
            {:registry (merge (m/default-schemas)
                              {String (m/-string-schema)
                               Long (m/-int-schema)})})
; => true

from malli.

ikitommi avatar ikitommi commented on June 11, 2024

... supporting classes out of the box would be nice, but not sure then there would be at least 3 ways to describe a string:

  • string? -> spec-like predicates
  • :string -> malli schema
  • String -> java Class

not sure if this makes the library easier to use.

from malli.

ikitommi avatar ikitommi commented on June 11, 2024

... maybe there should be a :instance schema? e.g.

(m/validate [:maybe [:instance datomic.db.Db]] my-db) ;; => true 

from malli.

jasonjckn avatar jasonjckn commented on June 11, 2024

When I started down this path, i was hoping to handle ALL classes, interfaces & protocols out-of-the-box e.g.

(extend-protocol m/IntoSchema
  java.lang.Class
  .... instance? ....
  clojure.imaginary.Protocol
  ..... satisfies? .......

But protocols don't have their own Class to dispatch off of, rather are persistent data structures, and

(extend-protocol m/IntoSchema
    clojure.lang.PersistentArrayMap

Seems a bit janky, given all that, so i'm a lot less enthusiastic my original idea

Also, to your point about the performance of satisfies? , folks may want fine grained control e.g. [:maybe [:instance MyProtocol]], [:maybe [:satisfies MyProtocol]],

I can send a PR for that if you'd like... but since this is so close to [:fn #(satisfies? P %)] maybe it doesn't warrant its own abstraction... am split 50/50 on this too, maybe it's just better to keep malli API leen.


"You can already add Class -> Schema via registry"
sure, but I still need something like :instance .

(m/validate [:tuple String Long]
            ["123" 123]
            {:registry (merge (m/default-schemas)
                              {datomic.db.Db [:maybe [:instance datomic.db.Db]]})})

from malli.

jasonjckn avatar jasonjckn commented on June 11, 2024

going to close this, while i'm going to commit this code to my own codebase, i don't feel like it's worthy of malli codebase yet... still needs hammock time for supporting all of classes, interfaces, protocols, etc — not just classes.

Please see #960 though, i'm still interested in the capability of -being able to do this-.

from malli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.