Markus Agwin / Dec 04 2018

Maybe patch?

Watching Rich Hickey's talk "Maybe Not" at Conj '18 (I suggest minute 24), I tried the current way of dealing with optional data.

(require '[clojure.spec.alpha :as s])
(s/def ::car (s/cat :make string?
                    :optional (s/? (s/cat :model string? :year int?))))

s/conform works perfect

(s/conform ::car '("Ford"))
(s/conform ::car '("Ford" "Mustang" 1964))

However, s/unform returns a nested list, which is not the expected behaviour

(s/unform ::car (s/conform ::car '("Ford" "Mustang" 1964)))

So I decided to apply Clojure patch #CLJ-2003

HIER KOMMT DIE PATCH MAGIC

Now, s/unform works as expected

(s/unform ::car (s/conform ::car '("Ford" "Mustang" 1964)))

Many users do not have experience with git and maven. It would be of great help if we could just write the following deps.edn

{:deps
 {org.clojure/clojure
   {:mvn/version "1.10.0-beta8"}
  org.clojure/spec.alpha
  {:mvn/version "0.2.176"
	 :patch ["https://dev.clojure.org/jira/secure/attachment/18340/CLJ-2003-corrected.patch" "00x1hd7mvv83gfn54n1i8nzh0w12cmp82zi21rh80yclylgs2f6z"]}}}
Extensible Data Notation