diff options
| author | unwox <me@unwox.com> | 2024-09-26 17:46:38 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-09-26 17:46:38 +0600 |
| commit | 9b82db238f9e2e02a76f95c793f8d6ef2387ecfd (patch) | |
| tree | cdb2a16d01f09553b560ab1034d53392d07bae42 /lib | |
init
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/array.fnl | 13 | ||||
| -rw-r--r-- | lib/macro.fnl | 18 | ||||
| -rw-r--r-- | lib/number.fnl | 6 | ||||
| -rw-r--r-- | lib/string.fnl | 11 |
4 files changed, 48 insertions, 0 deletions
diff --git a/lib/array.fnl b/lib/array.fnl new file mode 100644 index 0000000..11e4d2a --- /dev/null +++ b/lib/array.fnl @@ -0,0 +1,13 @@ +(import-macros {: reduce} :lib.macro) + +(fn concat [a b] + (local copy + (fn [a b] + (reduce + (fn [_ v c] + (table.insert c v) + c) + b a))) + (copy a b)) + +{: concat} diff --git a/lib/macro.fnl b/lib/macro.fnl new file mode 100644 index 0000000..f23b1fb --- /dev/null +++ b/lib/macro.fnl @@ -0,0 +1,18 @@ +(fn map [f l] + `(icollect [i# v# (ipairs ,l)] + (,f i# v#))) + +(fn filter [f l] + `(icollect [i# v# (ipairs ,l)] + (if (,f i# v#) + v# + nil))) + +(fn reduce [f l s] + `(accumulate [r# ,s + i# v# (ipairs ,l)] + (,f i# v# r#))) + +{: map + : filter + : reduce} diff --git a/lib/number.fnl b/lib/number.fnl new file mode 100644 index 0000000..61d8cc4 --- /dev/null +++ b/lib/number.fnl @@ -0,0 +1,6 @@ +(fn string->number [str] + (if str + (tonumber (pick-values 1 (str:gsub "[^0-9.]" ""))) + nil)) + +{: string->number} diff --git a/lib/string.fnl b/lib/string.fnl new file mode 100644 index 0000000..466dac9 --- /dev/null +++ b/lib/string.fnl @@ -0,0 +1,11 @@ +(fn split [string] + (accumulate [res [] v _ + (string:gmatch "%S+")] + (do + (table.insert res v) + res))) + +(fn ends-with [string end] + (= (string.sub string (- (# end))) end)) + +{: split : ends-with} |
