# WolframLang: Association, Misc

By Xah Lee. Date: . Last updated: .

xtodo work in progress

## Functions that Map to Values

Functions that work on lists, when used on association, they apply to the values. (keys are ignored)

e.g.

`Take`, `Select`, [see WolframLang: Association: Filter]

## Functions that Apply to Keys

• KeySort, KeySortBy — sort an association by its keys
• KeyMap — map a function over the keys in an association
• KeyValueMap — map a function over keys and values in an association

## Functions Operating on Lists of Associations

`Merge[{assoc1,assoc2 etc}, f]`
merges associations, applying function f to combine values with the same key. WARNING: f is applied to all keys, even unique keys.

f should be a function that takes one argument of List . (the number of items in the list is one to the count of associations). Item of the list is either a value of a single unique key, or values of the same key.

Merge
```xx = Association[ a -> 1, b -> 2 ];
yy = Association[ a -> 10, c -> 3 ];

(* merge. showing how the f works. note that f is applied to all key's values *)
Merge[ {xx, yy}, f ] === <|a -> f[{1, 10}], b -> f[{2}], c -> f[{3}]|>```
```xx = Association[ a -> 1, b -> 2 ];
yy = Association[ a -> 10, c -> 3 ];

(* merge. combine values to list *)
Merge[ {xx, yy}, List ] === <|a -> {{1, 10}}, b -> {{2}}, c -> {{3}}|>```
```xx = Association[ a -> 1, b -> 2 ];
yy = Association[ a -> 10, c -> 3 ];

(* merge. new key's value is the total their values *)
Merge[ {xx, yy}, Total ] === <|a -> 11, b -> 2, c -> 3|>```
`Merge[{key1 -> val1, key2 -> val2 etc}, f]`
merge a List of Rules .
• Catenate — catenate elements from multiple associations
• JoinAcross — do the analog of a database join on multiple associations
• Dataset — representation supporting general structured data queries

• Key — indicate a key within a part specification
• #name — a slot in a pure function that picks out value with key "name" in an association
• AssociationQ — test if an expression is a valid association

Elements of Associations

Pattern Matching with Associations

Functions That Create Associations

• Association — turn a list of rules into an association
• AssociationMap — create an association by applying a function to a list of keys
• AssociationThread — create an association from a list of keys and a list of values
• Counts, CountsBy — associate values with the number of times they occur
• PositionIndex — build an index of positions at which values occur
`GroupBy`
List To association list GroupBy