Wolfram Research

Function Repository Resource:

JoinMost

Source Notebook

An operator that joins in front of its arguments the sequence of lists it is provided

Contributed by: Seth J. Chandler

ResourceFunction["JoinMost"][list]

an operator that will join the sequence of lists it encounters with list.

Details and Options

The argument(s) need not have the head List. All subsequent expressions will be joined in front of it provided they have the same head.

Examples

Basic Examples

JoinMost uses Join to join its argument {3,4} with whatever else it encounters, which one may think of as Most of the Join:

In[1]:=
ResourceFunction["JoinMost"][{3, 4}][{5, 6, 7}, {8, 9, 10, 11}]
Out[1]=

JoinMost when used with an association as its argument will override key-value pairs from the sequence of lists it encounters if any of them have the same key:

In[2]:=
ResourceFunction["JoinMost"][<|"a" -> 0|>][
 Association["a" -> 7, "b" -> 9]]
Out[2]=

Scope

The operator created by JoinRest using an association can accept a sequence of associations and will override key-value pairs if and only if it encounters any association in the sequence with the same key:

In[3]:=
ResourceFunction["JoinMost"][<|"a" -> 0, "b" -> 0|>][
 Association["a" -> 7, "b" -> 9], Association["a" -> -8, "c" -> 3]]
Out[3]=

If JoinMost has no argument, it operates as an identity on the data it is given:

In[4]:=
ResourceFunction["JoinMost"][][Association["a" -> 7, "b" -> 9]]
Out[4]=

If JoinMost has a sequence of associations as its argument, it will use the last value for a key it confronts in that sequence to perform the override:

In[5]:=
ResourceFunction["JoinMost"][<|"a" -> 0|>, <|"a" -> 4, "c" -> -2|>][
 Association["a" -> 7, "b" -> 9], Association["a" -> -8, "c" -> 3]]
Out[5]=

Applications

JoinRest can be right composed with Counts to create an Association that coerces an answer for certain anticipated values:

In[6]:=
Query[Counts /* ResourceFunction[
    "JoinMost"][<|"a" -> Missing["not trusted"]|>]][{"a", "b", "a", "b", "a", "a", "a", "b"}]
Out[6]=

Properties and Relations

JoinMost works similarly to Merge with a Last combiner function:

In[7]:=
With[{data = {"a", "b", "a", "b", "a", "a", "a", "b"}, default = <|"a" -> 0|>}, SameQ[Query[Counts /* ResourceFunction["JoinMost"][default]][data], Merge[{Query[Counts][data], default}, Last]
  ]
 ]
Out[7]=

JoinMost is very similar to the resource function JoinRest. In JoinMost, its argument is placed last in the Join; in JoinRest, its argument is placed first in the Join.

Possible Issues

JoinMost, like Join, will fail to evaluate if the heads of the expressions to be joined differ from one another:

In[8]:=
ResourceFunction["JoinMost"][{1, 2, 3}][Association["a" -> 2]]
Out[8]=

Neat Examples

Why you should read code carefully before trusting the results :

In[9]:=
Query[Counts /* ResourceFunction["JoinMost"][
    Association[False -> 200]], #survived &][
 ExampleData[{"Dataset", "Titanic"}]]
Out[9]=

Resource History

See Also

License Information