From bdea62d872a534b5a9a24b42aa25aa627df1e2c5 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Wed, 21 Oct 2020 22:37:25 +0300 Subject: add more functions and doc --- core.fnl | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'core.fnl') diff --git a/core.fnl b/core.fnl index 1c84b26..e1f3ae0 100644 --- a/core.fnl +++ b/core.fnl @@ -16,14 +16,26 @@ sequential table, leaves it unchanged." (insert res [k v])) (if assoc? res tbl))) +(fn unseq [tbl] + (local res {}) + (each [_ [k v] (ipairs tbl)] + (tset res k v)) + res) + +(fn into [to from] + (match to + :vec (seq from) + :map (unseq from) + _ (error "unsupported table type" 2))) + (fn first [itbl] "Return first element of an indexed table." - (. itbl 1)) + (. (seq itbl) 1)) (fn rest [itbl] "Returns table of all elements of indexed table but the first one." - (let [[_ & xs] itbl] + (let [[_ & xs] (seq itbl)] xs)) @@ -49,7 +61,7 @@ sequential table, leaves it unchanged." (consj itbl x)))) -(fn* cons [x itbl] +(fn cons [x itbl] "Insert `x' to `itbl' at the front. Modifies `itbl'." (doto (or itbl []) (insert 1 x))) @@ -209,13 +221,13 @@ sorting tables first." )) {: seq + : into : mapv : mapkv : reduce : reduce-kv : conj : cons - : consj : first : rest : eq? -- cgit v1.2.3