Skip to main content
Added example output
Source Link
FoldPairList[{#2 > #1, Max[#1, #2]} &, {1, 1, 2, 5, 2, 2, 9, 1, 2, 11}] (* {False, True, True, False, False, True, False, False, True} *) 
FoldPairList[{#2 > #1, Max[#1, #2]} &, {1, 1, 2, 5, 2, 2, 9, 1, 2, 11}] 
FoldPairList[{#2 > #1, Max[#1, #2]} &, {1, 1, 2, 5, 2, 2, 9, 1, 2, 11}] (* {False, True, True, False, False, True, False, False, True} *) 
deleted 5 characters in body
Source Link
lirtosiast
  • 684
  • 6
  • 14
  • With {f[#2] - Count[#, #2], Append[#, #2]} &

    • Output f[#2] - Count[#,#2], the adjusted count of a variable #2 in an expression.
    • "Build up" the expression by appending #2.
  • With {Abs@Total[#2 - #1], #2} &:

    • Output the diagonal distance between a point and the accumulator.
    • Set the accumulator to the next point.
    • This does not use the full power of FoldPairList, and so can be written as BlockMap[...,2] in modern Mathematica.
  • Say you earn a certain income and pay federal, state, and local tax in that order, by some function f[taxRatef[remainingIncome, remainingIncome]taxRate].

    • Rest@FoldPairList[FoldPairList[{f@##, #2-f@##}&, grossIncome, taxRates] is how much you owe in each tax.
    • FoldList[#2-f@##&, grossIncome, taxRates] is your remaining income after each tax is applied.
    • FoldPair[{f@##, #2-f@##}&, grossIncome, taxRates] is you how much you owe in local tax.
    • Fold[#2-f@##&, grossIncome, taxRates] is your net income.
  • With {f[#2] - Count[#, #2], Append[#, #2]} &

    • Output f[#2] - Count[#,#2], the adjusted count of a variable #2 in an expression.
    • "Build up" the expression by appending #2.
  • With {Abs@Total[#2 - #1], #2} &:

    • Output the diagonal distance between a point and the accumulator.
    • Set the accumulator to the next point.
    • This does not use the full power of FoldPairList, and so can be written as BlockMap[...,2] in modern Mathematica.
  • Say you earn a certain income and pay federal, state, and local tax in that order, by some function f[taxRate, remainingIncome].

    • Rest@FoldPairList[{f@##, #2-f@##}&, grossIncome, taxRates] is how much you owe in each tax.
    • FoldList[#2-f@##&, grossIncome, taxRates] is your remaining income after each tax is applied.
    • FoldPair[{f@##, #2-f@##}&, grossIncome, taxRates] is you how much you owe in local tax.
    • Fold[#2-f@##&, grossIncome, taxRates] is your net income.
  • With {f[#2] - Count[#, #2], Append[#, #2]} &

    • Output f[#2] - Count[#,#2], the adjusted count of a variable #2 in an expression.
    • "Build up" the expression by appending #2.
  • With {Abs@Total[#2 - #1], #2} &:

    • Output the diagonal distance between a point and the accumulator.
    • Set the accumulator to the next point.
    • This does not use the full power of FoldPairList, and so can be written as BlockMap[...,2] in modern Mathematica.
  • Say you earn a certain income and pay federal, state, and local tax in that order, by some function f[remainingIncome, taxRate].

    • FoldPairList[{f@##, #2-f@##}&, grossIncome, taxRates] is how much you owe in each tax.
    • FoldList[#2-f@##&, grossIncome, taxRates] is your remaining income after each tax is applied.
    • FoldPair[{f@##, #2-f@##}&, grossIncome, taxRates] is you how much you owe in local tax.
    • Fold[#2-f@##&, grossIncome, taxRates] is your net income.
added 15 characters in body
Source Link
lirtosiast
  • 684
  • 6
  • 14

It is not surprising that FoldPairList is so obscuremysterious to many people. We usually think of Fold in the "building up" paradigm, whereas FoldPairList is most often useful in the "slicing off" paradigm.

It is not surprising that FoldPairList is so obscure. We usually think of Fold in the "building up" paradigm, whereas FoldPairList is most often useful in the "slicing off" paradigm.

It is not surprising that FoldPairList is mysterious to many people. We usually think of Fold in the "building up" paradigm, whereas FoldPairList is most often useful in the "slicing off" paradigm.

added 10 characters in body
Source Link
lirtosiast
  • 684
  • 6
  • 14
Loading
Source Link
lirtosiast
  • 684
  • 6
  • 14
Loading