Wolfram Language & System 10.3 (2015)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

FoldPairList

FoldPairList[f,y0,{a1,a2,}]
gives the list of successive obtained by applying f to pairs of the form , where at each step f returns .

FoldPairList[f,y0,list,g]
gives the list of successive values of .

FoldPairList[f,{a0,a1,a2,}]
is equivalent to FoldPairList[f,a0,{a1,a2,}].

DetailsDetails

  • The function f in FoldPairList[f,y0,list] always takes two arguments and is expected to return a pair of expressions.
  • The expression expr in FoldPairList[f,y0,expr] can be any nonatomic expression, with any head.
  • FoldPairList[f,y0,list] is equivalent to FoldPairList[f,y0,list,First].
  • FoldPairList[f,y0,{a1,,an}] returns a list of length n.
  • You can use Throw to exit from FoldPairList before it is finished.

ExamplesExamplesopen allclose all

Basic Examples  (7)Basic Examples  (7)

In[1]:=
Click for copyable input
Out[1]=
In[1]:=
Click for copyable input
Out[1]=
In[1]:=
Click for copyable input
Out[1]=
In[1]:=
Click for copyable input
Out[1]=

Partition a list into sublists of different lengths:

In[1]:=
Click for copyable input
Out[1]=

Break an amount of money into bills of given values:

In[1]:=
Click for copyable input
Out[1]=

Return both the quotients and the remainders at each step:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2015
(10.2)