FoldPairList
FoldPairList[f,y0,{a1,a2,…}]
gives the list of successive xi obtained by applying f to pairs of the form {yi-1,ai}, where at each step f returns {xi,yi}.
FoldPairList[f,y0,list,g]
gives the list of successive values of g[{xi,yi}].
FoldPairList[f,{a0,a1,a2,…}]
is equivalent to FoldPairList[f,a0,{a1,a2,…}].
Details
- The function f in FoldPairList[f,y0,list] always takes two arguments and is expected to return a pair {x,y} 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. FoldPairList[f,y0,{}] returns {}.
- You can use Throw to exit from FoldPairList before it is finished.
Examples
open allclose allBasic Examples (7)
Scope (2)
Use a list in the third argument:
Use an arbitrary head in the third argument:
By default, FoldPairList returns only the first elements of the pairs:
Use FoldPairList with fourth argument Last to get the second element of the successive pairs:
Generalizations & Extensions (1)
Use Throw to exit a FoldPairList:
Applications (2)
Properties & Relations (2)
Return the seed and all but the last elements of the third argument:
Return the list in the third argument:
FoldPairList returns one element less than FoldList:
Possible Issues (2)
The function in the first argument of FoldPairList must return a pair of expressions:
FoldPairList[f,y0,{}] returns an empty list, with no last element:
Therefore FoldPair[f,y0,{}] stays unevaluated:
Text
Wolfram Research (2015), FoldPairList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldPairList.html.
CMS
Wolfram Language. 2015. "FoldPairList." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FoldPairList.html.
APA
Wolfram Language. (2015). FoldPairList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FoldPairList.html