sequence>assoc! ( assoc seq map-quot: ( x -- ..y ) insert-quot: ( ..y assoc -- ) -- assoc )
Statistics > Computing histograms
Prev:sequence>assoc ( seq map-quot insert-quot exemplar -- assoc )
Next:sequence>hashtable ( seq map-quot insert-quot -- hashtable )


Vocabulary
math.statistics

Inputs and outputs
assocan assoc
seqa sequence
map-quota quotation
insert-quota quotation


Word description
Iterates over a sequence, allowing elements of the sequence to be added to an existing assoc. The map-quot gets passed each element from the sequence. Its outputs are passed along with the assoc being constructed to the insert-quot, which can modify the assoc in response.

Examples
! Iterate over a sequence and add the counts to an existing assoc USING: assocs prettyprint math.statistics kernel ; H{ { 97 2 } { 98 1 } } clone "aaabc" [ ] [ inc-at ] sequence>assoc! .
H{ { 97 5 } { 98 2 } { 99 1 } }


Definition
USING: generalizations math.statistics.private ;

IN: math.statistics

: sequence>assoc!
( assoc seq map-quot: ( x -- ..y ) insert-quot: ( ..y assoc -- ) -- assoc )
4 nrot (sequence>assoc) ; inline