Search code examples
validationclojureschemamalli

What is the difference between using : and ? in Malli?


When I try to validate for data types in Malli, what is the difference between using : and ? in Malli?

Like when I try for float, it fails for :float as invalid schema. But we are allowed to use :int and :string right? So why does it fail for :float?

And why does it work for float?


Here is an example :

(m/validate :float 788.89)
Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:138).
:malli.core/invalid-schema {:schema :float}
(m/validate float? 788.89)
=> true

How does this work?

(m/validate :int 788)
=> true
(m/validate int? 788)
=> true
(m/validate string? "89")
=> true
(m/validate :string "89")
=> true
(m/validate string? 89)
=> false

Solution

  • Malli by default does not know anything about :float. What's available is in malli.core/predicate-schemas.

    If you want to use :float, you have to use custom registry.