aboutsummaryrefslogtreecommitdiff
path: root/lib/collections.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-11 18:51:21 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-11 18:51:21 -0800
commite09f05a50cdb699029e8a4d5bafcfaade34157fd (patch)
treef216e71f7d7797706145f12349b48cd29d7c45ba /lib/collections.nom
parent06bf76f818382cdd33816073866f3cfd41609597 (diff)
Reshuffled all the library code into files that make more sense and
cleaned up some of the library code.
Diffstat (limited to 'lib/collections.nom')
-rw-r--r--lib/collections.nom13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/collections.nom b/lib/collections.nom
index e4b0eed..52e6675 100644
--- a/lib/collections.nom
+++ b/lib/collections.nom
@@ -1,5 +1,8 @@
+#..
+ This file contains code that supports manipulating and using collections like lists
+ and dictionaries.
+
use "lib/metaprogramming.nom"
-use "lib/utils.nom"
use "lib/control_flow.nom"
use "lib/operators.nom"
@@ -148,6 +151,13 @@ immediately:
return comprehension;
end)(nomsu)
+# Sorting:
+compile [sort %items] to: "table.sort(\(%items as lua))"
+compile [sort %items by %key_expr] to: ".."
+ nomsu.utils.sort(\(%items as lua), function(\(\% as lua))
+ return \(%key_expr as lua);
+ end)
+
action [%items sorted]:
%copy = (% for all %items)
sort %copy
@@ -156,6 +166,7 @@ action [%items sorted by %key]:
%copy = (% for all %items)
sort %copy by %key
return %copy
+
action [unique %items]:
[%k for %k=%v in {%=(yes) for all %items}]