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.
ResourceFunction["JoinMost"] is very similar to the resource function JoinRest:
In ResourceFunction["JoinMost"], its argument is placed last in the Join.
In the resource function JoinRest, its argument is placed first in the Join.

Examples

Basic Examples (2) 

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]=

When used with an Association as its argument, JoinMost 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 (3) 

The operator created by JoinMost using an association can accept sequence of associations and will override key-value pairs if and only 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 (1) 

JoinMost 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 (2) 

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 the resource function JoinRest, its argument is placed first in the Join.

Possible Issues (1) 

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 (1) 

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]=

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 24 June 2019

Related Resources

License Information