Skip to content

Commit 781d5ee

Browse files
committed
Code clean up for the release.
1 parent 85f7565 commit 781d5ee

File tree

8 files changed

+89
-103
lines changed

8 files changed

+89
-103
lines changed

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@ A minimalist data driven data model library, inspired by [Clojure Spec](https://
66
[![cljdoc badge](https://cljdoc.org/badge/minimallist/minimallist)](https://cljdoc.org/d/minimallist/minimallist/CURRENT)
77
[![project chat](https://img.shields.io/badge/slack-join_chat-brightgreen.svg)](https://clojurians.slack.com/archives/C012HUX1VPC)
88

9-
## Features
10-
11-
- validates and generates data,
12-
- fully data driven, models are hash-map based created via helpers,
13-
- support recursive definitions and sequence regex,
14-
- no macro, no static registry, pure functions,
15-
- relatively simple implementation, easy to read and modify,
16-
- cross platform (`.cljc`),
17-
- `valid?` runs in [Babashka](https://github.com/borkdude/babashka)
18-
19-
## Non-goals (for now)
20-
21-
- does not integrate with anything else,
22-
- does not try hard to be performant
23-
249
## Usage
2510

2611
```clojure
@@ -43,7 +28,27 @@ A minimalist data driven data model library, inspired by [Clojure Spec](https://
4328
;=> true
4429
```
4530

46-
See the [tests](test/) for more examples of how to use the helpers to build your models.
31+
## Features
32+
33+
- validates and generates data,
34+
- fully data driven, models are hash-map based created via helpers,
35+
- support recursive definitions and sequence regex,
36+
- no macro, no static registry, pure functions,
37+
- relatively simple implementation, easy to read and modify,
38+
- cross platform (`.cljc`),
39+
- `valid?` runs in [Babashka](https://github.com/borkdude/babashka)
40+
41+
## Non-goals (for now)
42+
43+
- does not integrate with anything else,
44+
- does not try hard to be performant
45+
46+
## Documentation
47+
48+
See the [latest documentation on cljdoc](https://cljdoc.org/d/minimallist/minimallist/CURRENT) for:
49+
- A general description of the Minimallist project.
50+
- How to use the helpers to build your models.
51+
- How to validate and generate your data.
4752

4853
## Status
4954

deps.edn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
;; Memo for deploying a new release:
1111
;; - change the version in pom.xml
12+
;; - update the pom.xml's dependencies:
13+
;; clj -Spom
1214
;; - build the jar:
1315
;; clojure -A:depstar -m hf.depstar.jar minimallist.jar -v
1416
;; - deploy:

pom.xml

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,45 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<groupId>minimallist</groupId>
6-
<artifactId>minimallist</artifactId>
7-
<version>0.0.2</version>
8-
<name>minimallist</name>
9-
10-
<description>A minimalist data driven data model library, inspired by Spec and Malli.</description>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>minimallist</groupId>
5+
<artifactId>minimallist</artifactId>
6+
<version>0.0.2</version>
7+
<name>Minimallist</name>
8+
<description>A minimalist data driven data model library, inspired by Spec and Malli.</description>
9+
<url>https://github.com/green-coder/minimallist</url>
10+
<scm>
1111
<url>https://github.com/green-coder/minimallist</url>
12-
13-
<scm>
14-
<url>https://github.com/green-coder/minimallist</url>
15-
<connection>
12+
<connection>
1613
scm:git:git://github.com/green-coder/minimallist.git
1714
</connection>
18-
</scm>
19-
20-
<licenses>
21-
<license>
22-
<name>Eclipse Public License v2.0</name>
23-
<url>http://www.eclipse.org/legal/epl-v20.html</url>
24-
</license>
25-
</licenses>
26-
27-
<developers>
28-
<developer>
29-
<id>green-coder</id>
30-
<name>Vincent Cantin</name>
31-
</developer>
32-
</developers>
33-
34-
<dependencies>
35-
<dependency>
36-
<groupId>org.clojure</groupId>
37-
<artifactId>clojure</artifactId>
38-
<version>1.10.1</version>
39-
</dependency>
40-
</dependencies>
41-
42-
<build>
43-
<sourceDirectory>src</sourceDirectory>
44-
<testSourceDirectory>test</testSourceDirectory>
45-
</build>
46-
47-
<repositories>
48-
<repository>
49-
<id>clojars</id>
50-
<url>https://repo.clojars.org/</url>
51-
</repository>
52-
</repositories>
53-
15+
</scm>
16+
<licenses>
17+
<license>
18+
<name>Eclipse Public License v2.0</name>
19+
<url>http://www.eclipse.org/legal/epl-v20.html</url>
20+
</license>
21+
</licenses>
22+
<developers>
23+
<developer>
24+
<id>green-coder</id>
25+
<name>Vincent Cantin</name>
26+
</developer>
27+
</developers>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.clojure</groupId>
31+
<artifactId>clojure</artifactId>
32+
<version>1.10.1</version>
33+
</dependency>
34+
</dependencies>
35+
<build>
36+
<sourceDirectory>src</sourceDirectory>
37+
<testSourceDirectory>test</testSourceDirectory>
38+
</build>
39+
<repositories>
40+
<repository>
41+
<id>clojars</id>
42+
<url>https://repo.clojars.org/</url>
43+
</repository>
44+
</repositories>
5445
</project>

src/minimallist/core.cljc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@
206206
([context model data]
207207
(boolean (-valid? context model data))))
208208

209-
(defn explain
209+
;; WIP, do not use!
210+
(defn ^:no-doc explain
210211
"Returns a structure describing what parts of the data are not matching the model."
211212
[model data])
212213

213-
(defn describe
214+
;; WIP, do not use!
215+
(defn ^:no-doc describe
214216
"Returns a descriptions of the data's structure using a hierarchy of hash-maps."
215217
([model data]
216218
(describe {} model data))
@@ -320,7 +322,8 @@
320322
;; TODO: Treat the attributes independently of the type of the node in which they appear.
321323
;; That's a kind of composition pattern a-la-unity.
322324

323-
(defn undescribe
325+
;; WIP, do not use!
326+
(defn ^:no-doc undescribe
324327
"Returns a data which matches a description."
325328
[model description])
326329

src/minimallist/generator.cljc

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545

4646

47-
48-
4947
(defn- find-stack-index [stack key]
5048
(loop [index (dec (count stack))
5149
elements (rseq stack)]
@@ -115,7 +113,12 @@
115113
:fn (:min-value count-model)
116114
nil)))))
117115

118-
(defn assoc-leaf-distance-visitor [model stack path]
116+
(defn assoc-leaf-distance-visitor
117+
"Associate an 'distance to leaf' measure to each node of the model.
118+
It is used as a hint on which path to choose when running out of budget
119+
in a budget-based data generation. It's very useful as well to avoid
120+
walking in infinite loops in the model."
121+
[model stack path]
119122
(let [distance (case (:type model)
120123
(:fn :enum) 0
121124
:map-of (let [key-distance (-> model :keys :model ::leaf-distance)
@@ -151,7 +154,10 @@
151154
(cond-> model
152155
(some? distance) (assoc ::leaf-distance distance))))
153156

154-
(defn assoc-min-cost-visitor [model stack path]
157+
(defn assoc-min-cost-visitor
158+
"Associate an 'minimun cost' measure to each node of the model.
159+
It is used as a hint during the budget-based data generation."
160+
[model stack path]
155161
(let [type (:type model)
156162
min-cost (case type
157163
(:fn :enum) (::min-cost model 1)
@@ -199,26 +205,10 @@
199205
(cond-> model
200206
(some? min-cost) (assoc ::min-cost min-cost))))
201207

202-
203-
(defn- preferably-such-that
204-
"A generator that tries to generate values satisfying a given predicate,
205-
but won't throw an tantrum if it can't."
206-
([pred gen]
207-
(preferably-such-that pred gen 10))
208-
([pred gen max-tries]
209-
(#'gen/make-gen (fn [rng size]
210-
(loop [tries-left max-tries
211-
rng rng
212-
size size]
213-
(if (zero? tries-left)
214-
(gen/call-gen gen rng size)
215-
(let [[r1 r2] (random/split rng)
216-
value (gen/call-gen gen r1 size)]
217-
(if (pred (rose/root value))
218-
(rose/filter pred value)
219-
(recur (dec tries-left) r2 (inc size))))))))))
220-
221-
(defn- rec-coll-size-gen [max-size]
208+
(defn- rec-coll-size-gen
209+
"Returns a generator of numbers between 0 and max-size
210+
with a gaussian random distribution."
211+
[max-size]
222212
(if (pos? max-size)
223213
(gen/fmap (fn [[x y]] (+ x y 1))
224214
(gen/tuple (gen/choose 0 (quot (dec max-size) 2))

src/minimallist/minicup.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns minimallist.minicup
1+
(ns ^:no-doc minimallist.minicup
22
(:require [minimallist.core :as m]
33
[minimallist.helper :as h]))
44

src/minimallist/minimap.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns minimallist.minimap
1+
(ns ^:no-doc minimallist.minimap
22
(:require [minimallist.core :as m]
33
[minimallist.helper :as h]))
44

@@ -8,7 +8,7 @@
88
(h/let ['model (h/alt [:fn (h/map [:type (h/val :fn)]
99
[:fn (h/fn fn?)])]
1010
[:enum (h/map [:type (h/val :enum)]
11-
[:values (h/set)])]
11+
[:values (h/set-of (h/fn any?))])]
1212
[:and-or (h/map [:type (h/enum #{:and :or})]
1313
[:entries (h/vector-of (h/map [:model (h/ref 'model)]))])]
1414
[:set-of (-> (h/map [:type (h/val :set-of)])

test/minimallist/generator_test.cljc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,6 @@
269269

270270
#__))
271271

272-
(deftest preferably-such-that-test
273-
(is (every? #{0 1 2}
274-
(-> (#'mg/preferably-such-that #{0 1 2} (tcg/choose 0 5))
275-
tcg/sample)))
276-
(is (every? #(<= 10 % 15)
277-
(-> (#'mg/preferably-such-that #{0 1 2} (tcg/choose 10 15))
278-
tcg/sample))))
279-
280272
(deftest budget-split-gen-test
281273
(is (every? (fn [[a b c]]
282274
(and (<= 0 a 5)
@@ -497,4 +489,7 @@
497489
(h/ref 'node))]
498490
(is (thrown? #?(:clj Exception :cljs js/Object) (tcg/sample (gen model))))))
499491

492+
;; TODO: [later] reuse the cat-ipsum model for parsing the output.
500493

494+
;; TODO: in the :alt node, introduce a property :occurrence for the generator.
495+
;; TODO: generate models, use them to generate data, should not stack overflow.

0 commit comments

Comments
 (0)