Comments (5)
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.
... 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 schemaString
-> java Class
not sure if this makes the library easier to use.
from malli.
... maybe there should be a :instance
schema? e.g.
(m/validate [:maybe [:instance datomic.db.Db]] my-db) ;; => true
from malli.
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.
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)
- Feature: Using Java classes as schemas HOT 2
- Not supported 3.1.0 openapi schema HOT 1
- Is it possible to represent an increasing sequence? HOT 1
- Parser losing metadata? HOT 1
- function guard should be instrumented by default HOT 1
- Nested map destructuring in `mx/defn` wraps extra collection
- qualified keywords in :keys in mx/defn fails macro schema validator. HOT 2
- `:double` generates Long if `:min` is Long
- `[:> Double/MAX_VALUE]` generates `Double/MAX_VALUE`
- Cannot generate values for regular expression schema HOT 2
- Function generators return constant function if seed provided
- Malli doesn't work with latest Cherry HOT 1
- A composite registry cannot be used a local registry HOT 1
- allow :error/fn or :error/message in {:optional t/f} to help define missing key error message
- How to: specify SCI `:classes`
- Datafy representation for reified schemas
- Add :min/:max limits to :map validator
- plantuml and dot transform fail with custom registry HOT 1
- OutOfMemoryError Java heap space exhausted with wrong schema
- `:?` doesn't work properly in function schemas in cljs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from malli.