summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/array.fnl43
-rw-r--r--lib/string.fnl2
2 files changed, 40 insertions, 5 deletions
diff --git a/lib/array.fnl b/lib/array.fnl
index 11e4d2a..9ed0d80 100644
--- a/lib/array.fnl
+++ b/lib/array.fnl
@@ -4,10 +4,45 @@
(local copy
(fn [a b]
(reduce
- (fn [_ v c]
- (table.insert c v)
- c)
+ (fn [_ v res]
+ (table.insert res v)
+ res)
b a)))
(copy a b))
-{: concat}
+(fn flip [a]
+ (collect [k v (pairs a)]
+ (values v k)))
+
+(fn diff [a b]
+ (local flip-b (flip b))
+ (reduce
+ (fn [_ v res]
+ (when (not (. flip-b v))
+ (table.insert res v))
+ res)
+ a []))
+
+(fn unique [a]
+ (var hash {})
+ (reduce
+ (fn [_ v res]
+ (when (not (. hash v))
+ (tset hash v true)
+ (table.insert res v))
+ res)
+ a []))
+
+(fn flatten [a]
+ (reduce
+ (fn [_ value rest]
+ (concat
+ rest
+ (if (= (type value) "table")
+ (flatten value)
+ [value])))
+ a []))
+
+(local join table.concat)
+
+{: concat : diff : unique : flatten : join}
diff --git a/lib/string.fnl b/lib/string.fnl
index d82c658..9ac6edd 100644
--- a/lib/string.fnl
+++ b/lib/string.fnl
@@ -19,4 +19,4 @@
(.. (trim (luna.utf.sub str 1 len)) (or ellipsis "...")))
""))
-{: split : ends-with : truncate}
+{: split : ends-with : trim : truncate}