From 7512a945b2be0c5c325891091b84514fc1fc499a Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Wed, 20 Mar 2024 15:24:44 +0530 Subject: [PATCH] Adding a nested DS example. --- examples/03-ds/nested_ds_companies.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/03-ds/nested_ds_companies.exs diff --git a/examples/03-ds/nested_ds_companies.exs b/examples/03-ds/nested_ds_companies.exs new file mode 100644 index 0000000..8cddb37 --- /dev/null +++ b/examples/03-ds/nested_ds_companies.exs @@ -0,0 +1,19 @@ +m = %{} + +# cm_emp = m["CoderMana"] +# cm_emp = (cm_emp || []) ++ ["G A"] +# Map.put m, "CoderMana", cm_emp + +# (or) + +m = update_in m, ["CoderMana"], fn (cm_emp) -> (cm_emp || []) ++ ["G A"] end +# update_in m, ["CoderMana"], fn (cm_emp) -> ["G A" | (cm_emp || [])] end + +# --- + +m = %{ + "Toshiba" => ["Bhautik", "Saraswati", "Nagaraj"], + "CoderMana" => ["Gaurav"], +} + +m = update_in m, ["CoderMana"], fn (cm_emp) -> (cm_emp ++ ["G A"]) end