Evaluate

Basic Examples

JoinRest uses
Join
to join its argument
{3,4}
with whatever else it encounters, which one may think of as the “Rest” of the
Join
:
[◼]
JoinRest
[{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
Join
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:
[◼]
JoinRest
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][Association["a"7,"b"9]]
In[]:=
a7,b9,c0
Out[]=

Scope

The operator created by JoinRest using an
Association
can accept sequence of associations:
[◼]
JoinRest
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][Association["a"7,"b"9],Association["a"-8,"c"3]]
In[]:=
a-8,b9,c3
Out[]=
If JoinRest has no argument, it operates as an identity on the data it is given:
[◼]
JoinRest
[][Association["a"7,"b"9]]
In[]:=
a7,b9
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:
[◼]
JoinRest
[\[LeftAssociation]"a"0\[RightAssociation],\[LeftAssociation]"a"4,"c"-2\[RightAssociation]][Association["b"9],Association["b"-8,"c"3]]
In[]:=
a4,c3,b-8
Out[]=

Applications

JoinRest can be right-composed with
Counts
to create an Association that obtains the number of every anticipated value in an expression:
QueryCounts/*
[◼]
JoinRest
[\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]][{"a","b","a","b","a","a","a","b"}]
In[]:=
a5,b3,c0
Out[]=

Properties and Relations

JoinRest works similarly to
Merge
with a
First
combiner function:
With{data={"a","b","a","b","a","a","a","b"},default=\[LeftAssociation]"a"0,"b"0,"c"0\[RightAssociation]},SameQQueryCounts/*
[◼]
JoinRest
[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
Join
; in JoinMost its argument is placed last in the
Join
.

Possible Issues

JoinRest, like
Join
, will fail to evaluate if the heads of the expressions to be joined differ from one another:
[◼]
JoinRest
[{1,2,3}][Association["a"2]]
In[]:=
Join
:Incompatible elements in Join[{1,2,3},a2] cannot be joined.
Join[{1,2,3},a2]
Out[]=

Neat Examples

Insert JoinRest to a pipeline of operators created by
Query
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[]:=
ModulenoMaleSurvivors=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=
[◼]
JoinRest
[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[]=