Function Repository Resource:

Slice

Source Notebook

An operator form of Part

Contributed by: Taliesin Beynon

ResourceFunction["Slice"][i,j,][expr]

gives expr[[i,j,]].

Details and Options

ResourceFunction["Slice"] represents an operator form of Part.

Examples

Basic Examples (3) 

Select the first element of a list using the operator form:

In[1]:=
ResourceFunction["Slice"][1][{2, 3}]
Out[1]=

An operator that selects the key in an Association:

In[2]:=
slicer = ResourceFunction["Slice"]["a"];

Extract the value of a:

In[3]:=
slicer[<|"a" -> 1, "b" -> 2|>]
Out[3]=

Extract the first two key/value pairs using the operator form:

In[4]:=
ResourceFunction["Slice"][;; 2][<|"a" -> 1, "b" -> 2, "c" -> 3|>]
Out[4]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 04 February 2019

License Information