diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-12 21:41:06 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-12 21:41:06 +0300 |
| commit | 368ecb9abf626de4dcad496db17b55b268997fc7 (patch) | |
| tree | 4fc194283675c066a367b59c9008e5e44472dd77 | |
| parent | 8cb6c1a5741f3f71cae18df1eedcf327ff99e718 (diff) | |
fix(core): support string in into
| -rw-r--r-- | cljlib-macros.fnl | 35 | ||||
| -rw-r--r-- | tests/macros.fnl | 9 |
2 files changed, 33 insertions, 11 deletions
diff --git a/cljlib-macros.fnl b/cljlib-macros.fnl index ae6f93e..90f2c54 100644 --- a/cljlib-macros.fnl +++ b/cljlib-macros.fnl @@ -344,19 +344,31 @@ namespaced functions. See `fn*' for more info." (= k# nil) :empty :table)))) (= t# :nil) :nil + (= t# :string) :string :else)))) (fn seq-fn [] - `(fn [tbl#] - (var assoc# false) - (let [res# [] - insert# table.insert] - (each [k# v# (pairs (or tbl# []))] - (if (and (not assoc#) - (not (= (type k#) :number))) - (set assoc# true)) - (insert# res# [k# v#])) - (if assoc# res# tbl#)))) + `(fn [col#] + (let [t# (type col#)] + (if (= t# :table) + (do (var assoc# false) + (let [res# [] + insert# table.insert] + (each [k# v# (pairs (or col# []))] + (if (and (not assoc#) + (not (= (type k#) :number))) + (set assoc# true)) + (insert# res# [k# v#])) + (if assoc# res# col#))) + (= t# :string) + (let [res# [] + char# utf8.char + insert# table.insert] + (each [_# b# (utf8.codes col#)] + (insert# res# (char# b#))) + res#) + (= t# :nil) nil + (error "expected table or string" 2))))) (fn empty [tbl] (let [table-type (table-type tbl)] @@ -417,6 +429,9 @@ namespaced functions. See `fn*' for more info." :seq (do (each [_# [k# v#] (ipairs (or from# []))] (tset to# k# v#)) to#) + :string (do (each [_# v# (ipairs (seq# from#))] + (insert# to# v#)) + to#) :table (do (each [k# v# (pairs (or from# []))] (tset to# k# v#)) to#) diff --git a/tests/macros.fnl b/tests/macros.fnl index 9b2e6ac..a9b41fe 100644 --- a/tests/macros.fnl +++ b/tests/macros.fnl @@ -50,7 +50,14 @@ (assert-eq (into b [1 2 3]) [1 2 3])) (let [a {} b []] - (assert-eq (into b {:a 1}) [[:a 1]])))) + (assert-eq (into b {:a 1}) [[:a 1]])) + + (let [a {} + b []] + (assert-eq (into a "vaiv") ["v" "a" "i" "v"]) + (assert-eq (into b "ваыв") ["в" "а" "ы" "в"])) + (assert-eq (into [] "vaiv") ["v" "a" "i" "v"]) + (assert-eq (into [] "ваыв") ["в" "а" "ы" "в"]))) (deftest let-variants (testing "when-let" |