Function Repository Resource:

Uncurry

Source Notebook

Reverse a Curry operation

Contributed by: Nikolay Murzin

ResourceFunction["Uncurry"][f,n]

represents an operator form of the function f of n arguments so that ResourceFunction["Uncurry"][f,n][x1,,xn] is equivalent to f[x1][xn].

ResourceFunction["Uncurry"][f]

represents an operator form of the function f of two arguments so that ResourceFunction["Uncurry"][f][x1,x2] is equivalent to f[x2][x1].

ResourceFunction["Uncurry"][f,{i1,,in}]

represents an operator form of the function f of n arguments so that ResourceFunction["Uncurry"][f,{i1,,in}][x1,,xn] is equivalent to f[xj1][xjn], where jk is the position of k in the permutation list {i1,,in}.

ResourceFunction["Uncurry"][f,k{i1,,in}]

represents a k-arguments operator form of the function f of n arguments so that ResourceFunction["Uncurry"][f,k{i1,,in}][x1,,xn] is equivalent to f[xj1][xjk], with kMax[{i1,,in}], where jk is the position of k in the permutation list {i1,,ik} with missing im filled in sequentially to form a complete permutation of length k.

Details and Options

{j1,,jk} is equal to InversePermutation[{i1,,in}].

Examples

Basic Examples (1) 

Uncurry a curried function:

In[1]:=
ResourceFunction["Uncurry"][Curry[f]][a, b][x, y]
Out[1]=
In[2]:=
ResourceFunction["Uncurry"][Curry[f, 3], 3][a, b, c][x, y]
Out[2]=
In[3]:=
ResourceFunction["Uncurry"][f, {3, 1, 2}][a, b, c]
Out[3]=
In[4]:=
ResourceFunction["Uncurry"][Curry[f, {3, 1, 4, 2}], {3, 1, 4, 2}][a, b, c, d][x, y]
Out[4]=
In[5]:=
ResourceFunction["Uncurry"][Curry[f, 5 -> {3, 1, 4, 2}], 5 -> {3, 1, 4, 2}][a, b, c, d, XXXX]
Out[5]=

Possible Issues (2) 

A curried function that ignores its arguments cannot be completely uncurried:

In[6]:=
ResourceFunction["Uncurry"][Curry[f, {3, 1}], {3, 1}][x, y, z]
Out[6]=

The function loses an argument depending on its position in the uncurried permutation list:

In[7]:=
ResourceFunction["Uncurry"][Curry[f, {3, 1}], {2, 3, 1}][x, y, z]
Out[7]=
In[8]:=
ResourceFunction["Uncurry"][Curry[f, {3, 1}], {3, 2, 1}][x, y, z]
Out[8]=
In[9]:=
ResourceFunction["Uncurry"][Curry[f, {3, 1}], {3, 1, 2}][x, y, z]
Out[9]=

Publisher

N. Murzin

Version History

  • 1.0.0 – 02 March 2020

Related Resources

License Information