Skip to content

Commit f2322e9

Browse files
committed
Renamed properties on the :transform node, and changed its structure.
1 parent 6385ef2 commit f2322e9

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/minimallist/core.cljc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@
132132
(-valid? context (:count-model model) (count data)))
133133
(implies (contains? model :condition-model)
134134
(-valid? context (:condition-model model) data)))
135-
:transform (and (implies (contains? model :condition-model)
136-
(-valid? context (:condition-model model) data))
137-
(-valid? context (:child-model model) ((:destruct model) data)))
135+
:transform (and (-valid? context (:outer-model model) data)
136+
(-valid? context (:inner-model model) ((:outer->inner model identity) data)))
138137
:let (-valid? (into context (:bindings model)) (:body model) data)
139138
:ref (-valid? context (get context (:key model)) data)))
140139

@@ -312,12 +311,11 @@
312311
(-valid? context (:condition-model model) data))}
313312
{:valid? false}))
314313
{:valid? false})
315-
:transform (if (implies (contains? model :condition-model)
316-
(-valid? context (:condition-model model) data))
317-
(let [description (-describe context (:child-model model) ((:destruct model) data))]
314+
:transform (if (-valid? context (:outer-model model) data)
315+
(let [description (-describe context (:inner-model model) ((:outer->inner model identity) data))]
318316
(if (:valid? description)
319317
{:valid? true
320-
:desc ((:construct model) (:desc description))}
318+
:desc ((:outer<-inner model identity) (:desc description))}
321319
{:valid? false}))
322320
{:valid? false})
323321
:let (-describe (into context (:bindings model)) (:body model) data)

src/minimallist/generator.cljc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
[stack walked-bindings]
101101
(map-indexed vector entries)))))
102102
:transform (-> [[stack walked-bindings] model]
103-
(reduce-update :child-model walk (conj path :child-model)))
103+
(reduce-update :inner-model walk (conj path :inner-model)))
104104
:let (let [[[stack' walked-bindings'] walked-body] (walk [(conj stack {:bindings (:bindings model)
105105
:path (conj path :bindings)})
106106
walked-bindings]
@@ -171,7 +171,7 @@
171171
(map (comp ::leaf-distance :model)))]
172172
(when (every? some? distances)
173173
(inc (reduce max 0 distances))))
174-
:transform (some-> (-> model :child-model ::leaf-distance) inc)
174+
:transform (some-> (-> model :inner-model ::leaf-distance) inc)
175175
:let (some-> (-> model :body ::leaf-distance) inc)
176176
:ref (let [key (:key model)
177177
index (find-stack-index stack key)
@@ -224,7 +224,7 @@
224224
(map (comp ::min-cost :model)))
225225
content-cost (when (every? some? vals) (reduce + vals))]
226226
(some-> content-cost (+ container-cost)))
227-
:transform (some-> (::min-cost (:child-model model)) inc)
227+
:transform (some-> (::min-cost (:inner-model model)) inc)
228228
:let (::min-cost (:body model))
229229
:ref (let [key (:key model)
230230
index (find-stack-index stack key)]
@@ -495,9 +495,9 @@
495495
inside-list? (gen/fmap (partial apply list))))))
496496
(contains? model :condition-model) (gen/such-that (partial m/valid? context (:condition-model model))))
497497

498-
:transform (cond->> (generator context (:child-model model) budget)
499-
(contains? model :construct) (gen/fmap (:construct model))
500-
(contains? model :condition-model) (gen/such-that (partial m/valid? context (:condition-model model))))
498+
:transform (->> (generator context (:inner-model model) budget)
499+
(gen/fmap (:outer<-inner model identity))
500+
(gen/such-that (partial m/valid? context (:outer-model model))))
501501

502502
:let (generator (merge context (:bindings model)) (:body model) budget)
503503

src/minimallist/helper.cljc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,16 @@
208208

209209
(defn transform
210210
"Transformation of a data matching the model.
211-
`destruct` is used during validation and parsing, and
212-
`construct` is used during parsing and generation."
213-
([model destruct]
214-
{:type :transform
215-
:child-model model
216-
:destruct destruct})
217-
([model destruct construct]
218-
(assoc (transform model destruct) :construct construct)))
211+
`outer-model` is the model viewed from outside this node.
212+
`inner-model` is the model used for the inside of the node.
213+
`outer->inner` is transforming data during validation and parsing, and
214+
`outer<-inner` is transforming data during parsing and generation."
215+
[outer-model inner-model outer->inner outer<-inner]
216+
{:type :transform
217+
:outer-model outer-model
218+
:inner-model inner-model
219+
:outer->inner outer->inner
220+
:outer<-inner outer<-inner})
219221

220222
(defn let
221223
"Model with local model definitions."

src/minimallist/minimap.cljc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
[:condition-model (h/ref 'model)])
6262
(h/with-condition (h/fn #(<= (:min %) (:max %)))))]
6363
[:transform (-> (h/map [:type (h/val :transform)]
64-
[:child-model (h/ref 'model)]
65-
[:destruct (h/fn fn?)])
66-
(h/with-optional-entries [:construct (h/fn fn?)]
67-
[:condition-model (h/ref 'model)]))]
64+
[:outer-model (h/ref 'model)]
65+
[:inner-model (h/ref 'model)])
66+
(h/with-optional-entries [:outer->inner (h/fn fn?)]
67+
[:outer<-inner (h/fn fn?)]))]
6868
[:let (h/map [:type (h/val :let)]
6969
[:bindings (h/map-of (h/fn any?)
7070
(h/ref 'model))]

test/minimallist/core_test.cljc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@
226226
[:div {:a 1} "hei" [:p {} {} "bonjour"]]]
227227

228228
;; transform
229-
(-> (h/transform (h/sequence-of (h/enum #{"A" "T" "G" "C"}))
230-
#(mapv str (seq %))
231-
#(apply str %))
232-
(h/with-condition (h/fn string?)))
229+
(h/transform (h/fn string?)
230+
(h/sequence-of (h/enum #{"A" "T" "G" "C"}))
231+
#(mapv str (seq %))
232+
#(apply str %))
233233
["" "A" "CGATCAT"]
234234
[:foobar "CGAUCAU" "AOEU"]
235235

@@ -452,10 +452,10 @@
452452
[1 "a" 2 "b" 3 "c"] :invalid]
453453

454454
;; transform
455-
(-> (h/transform (h/sequence-of (h/enum #{"A" "T" "G" "C"}))
456-
#(mapv str (seq %))
457-
#(apply str %))
458-
(h/with-condition (h/fn string?)))
455+
(h/transform (h/fn string?)
456+
(h/sequence-of (h/enum #{"A" "T" "G" "C"}))
457+
#(mapv str (seq %))
458+
#(apply str %))
459459
["" ""
460460
"A" "A"
461461
"CGATCAT" "CGATCAT"

test/minimallist/generator_test.cljc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,10 @@
427427
(is (every? (partial valid? model)
428428
(tcg/sample (gen model)))))
429429

430-
(let [model (-> (h/transform (h/sequence-of (h/enum #{"A" "T" "G" "C"}))
431-
#(mapv str (seq %))
432-
#(apply str %))
433-
(h/with-condition (h/fn string?)))]
430+
(let [model (h/transform (h/fn string?)
431+
(h/sequence-of (h/enum #{"A" "T" "G" "C"}))
432+
#(mapv str (seq %))
433+
#(apply str %))]
434434
(is (every? (partial valid? model)
435435
(tcg/sample (gen model)))))
436436

0 commit comments

Comments
 (0)