Is the value valid?λ︎
clojure.spec.alpha/valid?
takes two arguments
- a specification
- a value to test against the specification
clojure.spec.alpha/valid?
is a predicate function.
true
is returned if the value meets the specification, otherwise false
is returned.
Require the Clojure spec libraryλ︎
Set the namespace for the page and require clojure.spec.alpha library, setting the alias to spec
Using valid?λ︎
If the value is valid then a boolean true is returned. Experiment with different values and predicate functions.
using custom predicate functionsλ︎
Create fn
definitions to use as predicate functions. Any function that returns true or false can be used.
The custom predicate function may also be written in the shorter form of a fn
definition
Use def
to bind names to custom predicate functions if they are used more than once in the code base.
In this example a name is bound to a function that checks if a port is within the range of IANA registered networking ports.