summaryrefslogtreecommitdiff
path: root/cljlib-macros.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-12 21:41:06 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-12 21:41:06 +0300
commit368ecb9abf626de4dcad496db17b55b268997fc7 (patch)
tree4fc194283675c066a367b59c9008e5e44472dd77 /cljlib-macros.fnl
parent8cb6c1a5741f3f71cae18df1eedcf327ff99e718 (diff)
fix(core): support string in into
Diffstat (limited to 'cljlib-macros.fnl')
-rw-r--r--cljlib-macros.fnl35
1 files changed, 25 insertions, 10 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#)