WolframLang: Association, Misc

By Xah Lee. Date: . Last updated: .

xtodo work in progress

Functions that Map to Values

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

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

Functions that Apply to Keys

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 .


Elements of Associations

Pattern Matching with Associations

Functions That Create Associations

GroupBy

List To association list

GroupBy

WolframLang: Association (Key Value List)