Skip to content

Commit

Permalink
Add ApplyToObjectField to Object.m
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhinder committed Sep 13, 2013
1 parent 745868e commit 57d2efa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/Object.mt
Expand Up @@ -69,3 +69,11 @@ Test[
,
TestID->"JoinObjectField-Exists"
]

Test[
ApplyToObjectField[NewObject[Obj, {"Key1" -> 1, "Key2" -> 2}], "Key1", g]
,
Obj["Key1" -> g[1], "Key2" -> 2]
,
TestID->"ApplyToObjectField"
]
6 changes: 6 additions & 0 deletions Tools/CodeGen/Object.m
Expand Up @@ -25,6 +25,7 @@
GetObjectField;
AppendObjectField;
JoinObjectField;
ApplyToObjectField;

Begin["`Private`"];

Expand Down Expand Up @@ -62,6 +63,11 @@
JoinObjectField[obj_, field_String, values_List] :=
SetObjectField[obj, field, Join[GetObjectField[obj, field], values]]];

DefFn[
ApplyToObjectField[obj_, field_String, f_] :=
SetObjectField[obj, field, f[GetObjectField[obj, field]]]];


End[];

EndPackage[];

0 comments on commit 57d2efa

Please sign in to comment.