Skip to content

Commit

Permalink
Merge pull request #926 from metosin/catn-parse-unparse
Browse files Browse the repository at this point in the history
fix #925
  • Loading branch information
ikitommi authored Aug 8, 2023
2 parents df3ad51 + f86241a commit 94ab7b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

Malli is in well matured [alpha](README.md#alpha).

## UNRELEASED

* FIX: retain order with `:catn` unparse, fixes [#925](https://github.com/metosin/malli/issues/925)

## 0.11.0 (2023-04-12)

* BREAKING: remove map syntax: `mu/from-map-syntax`, `mu/to-map-syntax`. Note that AST syntax and lite syntax remain unchanged.
Expand Down
2 changes: 1 addition & 1 deletion src/malli/impl/regex.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
:malli.core/invalid))))

(defn catn-unparser [& unparsers]
(let [unparsers (into {} unparsers)]
(let [unparsers (apply array-map (mapcat identity unparsers))]
(fn [m]
(if (and (map? m) (= (count m) (count unparsers)))
(miu/-reduce-kv-valid (fn [coll tag unparser]
Expand Down
15 changes: 15 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2959,3 +2959,18 @@
(prefixer "g")
(prefixer "h")
(prefixer "i")) "xxx"))))))

(deftest -issue-925-test
(testing "order is retained with catn parse+unparse"
(let [schema [:catn
[:a :int]
[:b :int]
[:c :int]
[:d :int]
[:e :int]
[:f :int]
[:g :int]
[:h :int]
[:i :int]]
input [1 2 3 4 5 6 7 8 9]]
(is (= input (->> input (m/parse schema) (m/unparse schema)))))))

0 comments on commit 94ab7b9

Please sign in to comment.