Iterate over deepest values in a nested Association
Level[assoc, {-1}]
(* {0, "one", 2, 3, 4} *)
assoc /. Association -> (Values@*List) // Flatten
{0, "one", 2, 3, 4}
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> {bar[1], foo[3]}|>;
assoc2 /. Association -> (Values@*List) // Flatten
{foo[0], "one", 2, 3, bar[1], foo[3]}
Level[assoc2, {-1}]
{0, "one", 2, 3, 1, 3}
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
{-2}
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>