summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-02 21:10:36 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-03-02 21:10:36 -0800
commit782873797401693035c47040f43bdb82630c45fa (patch)
tree897c38804bfd84519f228fa4a8258f8c4b9d0f51 /hash.c
parent9175dc378d5b2a6da0810d17407c3decfa91206a (diff)
downloadtxr-782873797401693035c47040f43bdb82630c45fa.tar.gz
txr-782873797401693035c47040f43bdb82630c45fa.tar.bz2
txr-782873797401693035c47040f43bdb82630c45fa.zip
New function: group-map.
* hash.c (group_map): New function. (hash_init): group-map intrinsic registered. * hash.h (group_map): Declared. * tests/010/hash.tl: New test case. * txr.1: Documented together with group-by. Extra paren removed from group-by example.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 352f3f33..70471382 100644
--- a/hash.c
+++ b/hash.c
@@ -1667,6 +1667,12 @@ val group_by(val func, val seq, struct args *hashv_args)
}
}
+val group_map(val by_fun, val filter_fun, val seq, struct args *hashv_args)
+{
+ val hash = group_by(by_fun, seq, hashv_args);
+ return hash_update(hash, filter_fun);
+}
+
val group_reduce(val hash, val by_fun, val reduce_fun, val seq,
val initval, val filter_fun)
{
@@ -2135,6 +2141,7 @@ void hash_init(void)
reg_fun(intern(lit("hash-subset"), user_package), func_n2(hash_subset));
reg_fun(intern(lit("hash-proper-subset"), user_package), func_n2(hash_proper_subset));
reg_fun(intern(lit("group-by"), user_package), func_n2v(group_by));
+ reg_fun(intern(lit("group-map"), user_package), func_n3v(group_map));
reg_fun(intern(lit("group-reduce"), user_package),
func_n6o(group_reduce, 4));
reg_fun(intern(lit("hash-update"), user_package), func_n2(hash_update));