diff options
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 45 |
1 files changed, 39 insertions, 6 deletions
@@ -53977,9 +53977,10 @@ with the value returned by as the datum. This value is also returned. -.coNP Function @ group-by +.coNP Functions @ group-by and @ group-map .synb -.mets (group-by < func < sequence << option *) +.mets (group-by < by-fun < sequence << option *) +.mets (group-map < by-fun < filter-fun < sequence << option *) .syne .desc The @@ -53992,7 +53993,7 @@ list or vector. Entries of the hash table are not elements of but lists of elements of .metn sequence . The function -.meta func +.meta by-fun is applied to each element of .meta sequence @@ -54007,16 +54008,48 @@ if any, consist of the same keywords that are understood by the .code hash function, and determine the properties of the hash. -.TP* Example: +The +.code group-map +fun extends the semantics of +.code group-by +with a filtering step. It groups the elements of +.meta sequence +in exactly the same manner, using +.metn by-fun . +These lists of elements are then passed to +.meta filter-fun +whose return values become the values associated with the hash table keys. + +The effect of +.code group-map +may be obtained by a combination of +.code group-by +and +.code hash-update +according to the following equivalence: + +.verb + (group-map bf ff seq) <--> (let ((h (group-by bf seq))) + (hash-update h ff)) +.brev + +.TP* Examples: Group the integers from 0 to 10 into three buckets keyed on 0, 1 and 2 according to the modulo 3 congruence: .verb - (group-by (op mod @1 3) (range 0 10))) - + (group-by (op mod @1 3) (range 0 10)) -> #H(() (0 (0 3 6 9)) (1 (1 4 7 10)) (2 (2 5 8))) .brev +Same as above, but associate the keys with the sums of the +buckets: + +.verb + [group-map (op mod @1 3) sum (range 0 10)] + -> #H(() (0 18) (1 22) (2 15)) +.brev + .coNP Function @ group-reduce .synb .mets (group-reduce < hash < classify-fun < binary-fun < seq |