Tommi Reiman (https://twitter.com/ikitommi) will be presenting Malli
(https://github.com/metosin/malli) is a fresh new data-driven data
validation and specification library for Clojure/Script. In this talk,
Tommi will give a quick introduction to Malli, compare it to prior art
including Plumatic Schema and clojure.spec and demonstrate how to
elegantly solve real-world problems with it. Also, peek beyond the
runtime validation.
2. a new data validation and specification
library for Clojure/Script. It provides unified
tools for building data-driven schema systems
covering schema definition, validation, (human)
errors, value and schema transformation, value and
schema generation, registries and much more.
https://github.com/metosin/malli
Malli
6. (def Address
[:map
[:id string?]
[:tags [:set keyword?]]
[:address
[:map
[:street string?]
[:city string?]
[:zip int?]
[:latlon [:tuple double? double?]]]]])
Hiccup syntax
Just data and functions
Maps are open
by default
Keys are
required by
default
Malli
Ordered
Keys
13. Registries
• Schema types are looked from a registry
• Registry is passed as explicit option into schema functions
• Default registry has ~100 types and is immutable
• Other registry types: mutable, dynamic, lazy, local and composite
• Special JVM / Closure compiler option to swap the default registry
• Default to global mutable registry in Malli 1.0.0?
21. Coercion
• We are dealing with various data sources with different capabilities,
e.g. JSON,YAML and XML data
• We need to decode from X to EDN and encode from EDN to X’
• … or just apply default values. Or convert strings into keyword keys
• Malli has fast two-way interceptor-based transformers
• Transforming based on Schema type and properties
27. Inferring values
• Opposite of GeneratingValues - return a Schema that validates
against the sample values
• Crawled legacy MongoDB collection (5+ years of accumulated stuff)
• For each value, inferred a schema + accumulated schema union
• All documents have timestamps —>Temporal Schema index!
29. Serialising Schemas
• Thanks to SCI (https://github.com/borkdude/sci) and Edamame
(https://github.com/borkdude/edamame), mostly all schemas can be
• Thanks to SCI (https://github.com/borkdude/sci) and Edamame
(https://github.com/borkdude/edamame), mostly all schemas can be
persisted (and read back) to EDN
• Works with all of clj (JVM & GraalVM) and cljs, no eval needed
• Big leverage in building truly dynamic systems
• Playground at malli.io
32. malli.util
• Schemas can be transformed, just like data
• Pre- & postwalk for generic walking over schemas
• update-properties, get, assoc, update, get-in, assoc-in, update-in, dissoc,
select-keys, …
• subschemas for
• Backed by the Schema & LensSchema protocols
36. Function Schemas
• (Higher order) functions can also be described with Malli
• Any existing ClojureVar can be annotated with Malli Schemas
• Support multi-rarities with custom return values for each
• Does not support varargs (WIP, the sequence schemas)
• Integrates to CLJ-kondo, plumatic schema style inline schemas WIP
• Aave, Ghostwheel-port for Malli (https://github.com/teknql/aave)
37. CLJS
• Designed to be light, DCE can remove most of the unneeded core
• Starts from few kilos zipped (validation with minimal registry)
41. Malli 1.0.0
• Support for sequence schemas (WIP, Pauli)
• Support for Schema parsing
• Protocol-based Fast Schema Inferrer
• Describe Malli Schemas with Malli (recall spec-of-specs)
• Expound-grade pretty printer (WIP)
• Proper documentation
• Re-visit some design decision (including the global registry)
43. Designing with Malli
• Where was the designing part??? ;)
• Malli in a clean slate fusion of the best parts of existing libraries
(plumatic schema and clojure.spec)
• In alpha, under active development
• Lot’s of ideas, so little (extra) time, help welcome
• Try reitit-malli to get started…