diff options
Diffstat (limited to 'Tools/MathematicaMisc/MapLookup.m')
-rw-r--r-- | Tools/MathematicaMisc/MapLookup.m | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Tools/MathematicaMisc/MapLookup.m b/Tools/MathematicaMisc/MapLookup.m index 1711cdf..ee0c85b 100644 --- a/Tools/MathematicaMisc/MapLookup.m +++ b/Tools/MathematicaMisc/MapLookup.m @@ -4,6 +4,7 @@ BeginPackage["MapLookup`", {"Errors`"}]; lookup::usage = ""; mapContains::usage = ""; mapReplace::usage = ""; +mapReplaceAdd::usage = ""; mapValueMap::usage = ""; lookupDefault::usage = ""; mapValueMapMultiple::usage = ""; @@ -59,6 +60,13 @@ mapReplace[map_, key_, value_] := VerifyMap[map]; Map[If[First[#] === key, key -> value, #] &, map]]; +mapReplaceAdd[map_, key_, value_] := + Module[{}, + VerifyMap[map]; + If[mapContains[map, key], + mapReplace[map, key, value], + mapAdd[map, key, value]]]; + mapAdd[map_, key_, value_] := Module[{}, VerifyMap[map]; |