Wolfram Research

Function Repository Resource:

SetComplementMap (1.0.0) current version: 1.1.0 »

Source Notebook

Apply a function to elements at certain positions and another function to the rest of the elements

Contributed by: Faizon Zaman

ResourceFunction["SetComplementMap"][f1,f2,list,pos]

applies f1 to elements in list at positions pos and applies f2 to the rest of the elements.

Examples

Basic Examples (2) 

Color numbers at particular positions red and color the rest blue:

In[1]:=
positions = Sort@RandomSample[Range[10], 5]
Out[1]=
In[2]:=
ResourceFunction["SetComplementMap"][Style[#, Red] &, Style[#, Blue] &, Range[10], positions]
Out[2]=

Rotate strings in a list and style them red while coloring the rest of the elements blue:

In[3]:=
list = {1, 2, "three", 4, "five", 6};
spositions = Position[list, _String];
ResourceFunction["SetComplementMap"][
 Rotate[Style[#, Red], 180 Degree] &, Style[#, Blue] &, list, spositions]
Out[5]=

Scope (1) 

Modify words in text in two ways:

In[6]:=
StringRiffle@
 ResourceFunction["SetComplementMap"][ToUpperCase, StringReverse, TextWords[ResourceData["Gettysburg Address"]], Sort@RandomInteger[{1, 258}, 100]]
Out[6]=

Publisher

Faizon Zaman

Version History

  • 1.1.0 – 27 November 2023
  • 1.0.0 – 19 July 2022

Related Resources

License Information