Does a value conform to a specification?
clojure.spec.alpha/conform
takes two arguments
- a specification
- a value to test against the specification
:clojure.spec.alpha/invalid
is returned when a value does not conform to a specification.
If the value does conform to the specification, then the value is returned. This value is referred to as a conformed value.
Require the Clojure spec library
Set the namespace for the page and require clojure.spec.alpha library, setting the alias to spec
(ns practicalli.clojure.specifications
(:require [clojure.spec.alpha :as spec]))
Using conform
If the value conforms to the spec, a conformed value is returned
(spec/conform odd? 101)
When a value does not conform to a spec, the value :clojure.spec.alpha/invalid
is returned
(spec/conform even? 101)
(spec/conform integer? 1)
(spec/conform seq? [1 2 3])
(spec/conform seq? (range 10))
(spec/conform map? {})
(spec/conform map? (hash-map :a 1 :b 2))
当前内容版权归 practicalli 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 practicalli .