Skip to content

Commit

Permalink
Fixed up MapAt a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
b3m2a1 committed Oct 19, 2018
1 parent 576e0e8 commit d234ccb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
9 changes: 6 additions & 3 deletions HashTableInterface.m
Expand Up @@ -231,8 +231,11 @@



HashTableMapAt[f_, h:HashTable[ht_System`Utilities`HashTable], s__]:=
(HashTableMapAt[f, ht, s]; h);
HashTableMapAt[f_, h:HashTable[ht_System`Utilities`HashTable], s_]:=
Scan[
System`Utilities`HashTableMapAt[ht, #, f]&,
Flatten@{s}
]


(* ::Subsubsubsection::Closed:: *)
Expand Down Expand Up @@ -578,7 +581,7 @@



ht_HashTable?HashTableQ["Mutate"[fn_, k__]]:=
ht_HashTable?HashTableQ["MapAt"[fn_, k__]]:=
HashTableMapAt[fn, ht, k];


Expand Down
42 changes: 29 additions & 13 deletions HashTableInterface.nb
Expand Up @@ -473,19 +473,22 @@ Cell["\[LeftCeiling]MapAt\[RightFloor]", "CodeSubsubsubsection",

Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"HashTableMapAt", "[",
RowBox[{"f_", ",", " ",
RowBox[{"h", ":",
RowBox[{"HashTable", "[", "ht_System`Utilities`HashTable", "]"}]}], ",",
" ", "s__"}], "]"}], ":=", "\n", "\t",
RowBox[{"(",
RowBox[{"HashTableMapAt", "[",
RowBox[{"f_", ",", " ",
RowBox[{"h", ":",
RowBox[{"HashTable", "[", "ht_System`Utilities`HashTable", "]"}]}], ",",
" ", "s_"}], "]"}], ":=", "\n", "\t",
RowBox[{"Scan", "[", "\n", "\t\t",
RowBox[{
RowBox[{
RowBox[{"HashTableMapAt", "[",
RowBox[{"f", ",", " ", "ht", ",", " ", "s"}], "]"}], ";", " ", "h"}],
")"}]}], ";"}]], \
RowBox[{"System`Utilities`HashTableMapAt", "[",
RowBox[{"ht", ",", " ", "#", ",", " ", "f"}], "]"}], "&"}], ",", "\n",
"\t\t",
RowBox[{"Flatten", "@",
RowBox[{"{", "s", "}"}]}]}], "\n", "\t\t",
"]"}]}]], \
"CodeInput",ExpressionUUID->"e13b8fd7-efeb-4f68-a054-807cbea1371a"]
}, Closed]],
}, Open ]],

Cell[CellGroupData[{

Expand Down Expand Up @@ -1157,7 +1160,7 @@ Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"ht_HashTable", "?", "HashTableQ"}], "[",
RowBox[{"\"\<Mutate\>\"", "[",
RowBox[{"\"\<MapAt\>\"", "[",
RowBox[{"fn_", ",", " ", "k__"}], "]"}], "]"}], ":=", "\n", "\t",
RowBox[{"HashTableMapAt", "[",
RowBox[{"fn", ",", " ", "ht", ",", " ", "k"}], "]"}]}],
Expand Down Expand Up @@ -1211,7 +1214,7 @@ Cell[BoxData[
"]"}]}]], \
"CodeInput",ExpressionUUID->"b37e21aa-6f87-4098-8322-2a3b849f6317"]
}, Closed]]
}, Closed]],
}, Open ]],

Cell[CellGroupData[{

Expand Down Expand Up @@ -1722,6 +1725,19 @@ Cell[BoxData[
RowBox[{"1", "\[Rule]", "3"}]}], "\[RightAssociation]"}]], "Output",
CellLabel->
"Out[40]=",ExpressionUUID->"d1280c34-5a25-4e2d-a652-d4c5e126ac85"]
}, Open ]],

Cell[CellGroupData[{

Cell[BoxData[
RowBox[{
RowBox[{"ht", "[", "\"\<sampleKey\>\"", "]"}], "=",
RowBox[{"RandomReal", "[", "]"}]}]], "Input",
CellLabel->"In[41]:=",ExpressionUUID->"704330c5-eded-4c33-aab7-383334510c0e"],

Cell[BoxData["0.7515943459993164`"], "Output",
CellLabel->
"Out[41]=",ExpressionUUID->"bd73ef1a-93f8-4915-a507-c60dc420d2a7"]
}, Open ]]
},
WindowSize->{808, 755},
Expand Down

0 comments on commit d234ccb

Please sign in to comment.