Basic Examples
Basic Examples
JoinRest uses to join its argument with whatever else it encounters, which one may think of as the “Rest” of the :
{3,4}
[{3,4}][{5,6,7},{8,9,10,11}]
In[]:=
{3,4,5,6,7,8,9,10,11}
Out[]=
JoinRest applied to an association creates an operator that will add key-value pairs to the of the argument it is passed, but only if those joined associations fail to contain a key present in the association to which JoinRest was applied:
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][Association["a"7,"b"9]]
In[]:=
a7,b9,c0
Out[]=
Scope
Scope
The operator created by JoinRest using an can accept sequence of associations:
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][Association["a"7,"b"9],Association["a"-8,"c"3]]
In[]:=
a-8,b9,c3
Out[]=
If JoinRest has no argument, it operates as an identity on the data it is given:
[][Association["a"7,"b"9]]
In[]:=
a7,b9
Out[]=
If JoinRest has a sequence of associations as its argument, it will use the last value for any key it encounters in that sequence as a basis for adding key-value pairs:
[\[LeftAssociation]"a"0\[RightAssociation],\[LeftAssociation]"a"4,"c"-2\[RightAssociation]][Association["b"9],Association["b"-8,"c"3]]
In[]:=
a4,c3,b-8
Out[]=
Applications
Applications
JoinRest can be right-composed with to create an Association that obtains the number of every anticipated value in an expression:
QueryCounts/*
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][{"a","b","a","b","a","a","a","b"}]
In[]:=
a5,b3,c0
Out[]=
Properties and Relations
Properties and Relations
JoinRest works similarly to with a combiner function:
With{data={"a","b","a","b","a","a","a","b"},default=\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]},SameQQueryCounts/*
[default][data],Merge[{Query[Counts][data],default},First]
In[]:=
True
Out[]=
JoinRest is very similar to the resource function JoinMost. In JoinRest its argument is placed first in the ; in JoinMost its argument is placed last in the .
Possible Issues
Possible Issues
JoinRest, like , will fail to evaluate if the heads of the expressions to be joined differ from one another:
[{1,2,3}][Association["a"2]]
In[]:=
Join[{1,2,3},a2]
Out[]=
Neat Examples
Neat Examples
Insert JoinRest to a pipeline of operators created by such that the count of various categories that survived and died on the Titanic defaults to 0 :
formatting=Row[{Labeled[#1,"ugly"],Labeled[#2,"nicer"]},Spacer[6]]&;
In[]:=
ModulenoMaleSurvivors=Query[Select[Not[#sex==="male"&&#survived]&]][ExampleData[{"Dataset","Titanic"}]],uglyQuery,prettyQuery,survivedString=(If[#survived,"survived","died"]&),f1=GroupBy[#class&],f2=GroupBy[#sex&]/*KeySort,f3=Counts/*KeySort,joiner=
[Association["survived"0,"died"0]],uglyQuery=Query[f1,f2,f3,survivedString];prettyQuery=Query[f1,f2,Insert[f3,joiner,2],survivedString];formatting[uglyQuery[noMaleSurvivors],prettyQuery[noMaleSurvivors]]
In[]:=
Out[]=