SlideShare a Scribd company logo
1 of 4
Download to read offline
CHEAT-SHEET
Folding
#2
โˆถ
/ 
๐’‚๐ŸŽ โˆถ
/ 
๐’‚๐Ÿ โˆถ
/ 
๐’‚๐Ÿ โˆถ
/ 
๐’‚๐Ÿ‘
๐’‡
/ 
๐’‚๐ŸŽ ๐’‡
/ 
๐’‚๐Ÿ ๐’‡
/ 
๐’‚๐Ÿ ๐’‡
/ 
๐’‚๐Ÿ‘ ๐’†
@philip_schwarz
slides by https://fpilluminated.com/
โˆถ
/ 
๐‘Ž0 โˆถ
/ 
๐‘Ž1 โˆถ
/ 
๐‘Ž2 โˆถ
/ 
๐‘Ž3
๐‘“
/ 
๐‘“ ๐‘Ž3
/ 
๐‘“ ๐‘Ž2
/ 
๐‘“ ๐‘Ž1
/ 
๐‘ ๐‘Ž0
๐‘“
/ 
๐‘Ž0 ๐‘“
/ 
๐‘Ž1 ๐‘“
/ 
๐‘Ž2 ๐‘“
/ 
๐‘Ž3 ๐‘
๐‘Ž0: (๐‘Ž1: ๐‘Ž2: ๐‘Ž3: )
๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3
var ๐‘Ž๐‘๐‘ = ๐‘
foreach(๐‘Ž in ๐‘Ž๐‘ )
๐‘Ž๐‘๐‘ = ๐‘“(๐‘Ž๐‘๐‘, ๐‘Ž)
return ๐‘Ž๐‘๐‘
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘Ž๐‘ 
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ ๐‘Ž๐‘ 
๐‘Ž๐‘  = [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ โˆท ๐›ผ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ = ๐‘
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘ฅ: ๐‘ฅ๐‘  = ๐‘“ ๐‘ฅ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘ฅ๐‘ 
๐‘“๐‘œ๐‘™๐‘‘๐‘™ โˆท ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ = ๐‘
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ ๐‘ฅ: ๐‘ฅ๐‘  = ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘ ๐‘ฅ ๐‘ฅ๐‘ 
๐‘Ÿ๐‘’๐‘๐‘™๐‘Ž๐‘๐‘’:
โˆถ ๐‘ค๐‘–๐‘กโ„Ž ๐‘“
๐‘ค๐‘–๐‘กโ„Ž ๐‘
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“ ๐‘Ž0 ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž2, ๐‘Ž3]))
๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž3])))
๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [ ]))))
๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 ๐‘)))
๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 ๐‘)))
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 [๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 [๐‘Ž2, ๐‘Ž3]
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 [๐‘Ž3]
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3 [ ]
๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3
Programmatic definition of right fold and left fold
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ associates ๐‘“ from the right
๐‘“๐‘œ๐‘™๐‘‘๐‘™ associates ๐‘“ from the left
โˆถ
/ 
๐‘Ž0 โˆถ
/ 
๐‘Ž1 โˆถ
/ 
๐‘Ž2 โˆถ
/ 
๐‘Ž3
๐‘“
/ 
๐‘“ ๐‘Ž3
/ 
๐‘“ ๐‘Ž2
/ 
๐‘“ ๐‘Ž1
/ 
๐‘ ๐‘Ž0
๐‘“
/ 
๐‘Ž0 ๐‘“
/ 
๐‘Ž1 ๐‘“
/ 
๐‘Ž2 ๐‘“
/ 
๐‘Ž3 ๐‘
๐‘Ž0: (๐‘Ž1: ๐‘Ž2: ๐‘Ž3: )
๐‘“(๐‘“ ๐‘“ ๐‘“ ๐‘, ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3)
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘Ž๐‘ 
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž๐‘ 
๐‘Ž๐‘  = [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3]
๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘))))
๐‘“๐‘œ๐‘™๐‘‘๐‘™ = ๐‘; ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘ฅ๐‘  โงบ [๐‘ฅ] = ๐‘“(๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘ฅ๐‘  , ๐‘ฅ)
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ = ๐‘; ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘ฅ โงบ ๐‘ฅ๐‘  = ๐‘“(๐‘ฅ, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ(๐‘ฅ๐‘ ))
๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3 ,
๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0, ๐‘Ž1, ๐‘Ž2 , ๐‘Ž3
๐‘“(๐‘“(๐‘“๐‘œ๐‘™๐‘‘๐‘™ [๐‘Ž0, ๐‘Ž1] , ๐‘Ž2), ๐‘Ž3)
๐‘“ ๐‘“ ๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3
๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ [ ] , ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3
๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘, ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3])
๐‘“(๐‘Ž0, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž1, ๐‘Ž2, ๐‘Ž3]))
๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž2, ๐‘Ž3])))
๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž3]))))
๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([])))))
๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘))))
Mathematical definition of right fold and left fold
๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ associates ๐‘“ from the right
๐‘“๐‘œ๐‘™๐‘‘๐‘™ associates ๐‘“ from the left
๐‘ฅ = the Birst element
๐‘ฅs = all but the Birst element
๐‘ฅ = the last element
๐‘ฅ๐‘  = all but the last element
https://fpilluminated.com/
based
on

More Related Content

Similar to Folding Cheat Sheet #2 - second in a series

Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersiaPenjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
bisma samudra
ย 
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersiaPenjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
bisma samudra
ย 
Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007
Demetrio Ccesa Rayme
ย 
Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007
Demetrio Ccesa Rayme
ย 
Relativity
RelativityRelativity
Relativity
edgardoangeles1
ย 
Relativity
RelativityRelativity
Relativity
edgardoangeles1
ย 

Similar to Folding Cheat Sheet #2 - second in a series (20)

Ley de composiciรณn interna algebra ii
Ley de composiciรณn interna algebra iiLey de composiciรณn interna algebra ii
Ley de composiciรณn interna algebra ii
ย 
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 32018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
ย 
Ley de composiciรณn interna algebra ii
Ley de composiciรณn interna algebra iiLey de composiciรณn interna algebra ii
Ley de composiciรณn interna algebra ii
ย 
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 32018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 1 Rombel 3
ย 
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersiaPenjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
ย 
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersiaPenjelasan Integral Lipat dua dan Penerapan pada momen inersia
Penjelasan Integral Lipat dua dan Penerapan pada momen inersia
ย 
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ… ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ย 
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ… ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ฮ˜ฮตฯ‰ฯฮฏฮฑ - ฮŸฯฮนฯƒฮผฮฟฮฏ - ฮ ฯฮฟฯ„ฮฌฯƒฮตฮนฯ‚ 2021 - ฮ“ ฮ›ฯ…ฮบฮตฮฏฮฟฯ…
ย 
Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007
ย 
Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007Semana 24 funciones iv รกlgebra uni ccesa007
Semana 24 funciones iv รกlgebra uni ccesa007
ย 
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptxSUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
ย 
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptxSUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
SUEC ้ซ˜ไธญ Adv Maths (Permutation) (Part 1).pptx
ย 
TABLA CENTROIDE .pdf
TABLA CENTROIDE .pdfTABLA CENTROIDE .pdf
TABLA CENTROIDE .pdf
ย 
TABLA CENTROIDE .pdf
TABLA CENTROIDE .pdfTABLA CENTROIDE .pdf
TABLA CENTROIDE .pdf
ย 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
ย 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
ย 
Relativity
RelativityRelativity
Relativity
ย 
Relativity
RelativityRelativity
Relativity
ย 
State space design
State space designState space design
State space design
ย 
State space design
State space designState space design
State space design
ย 

More from Philip Schwarz

N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets Cats
Philip Schwarz
ย 

More from Philip Schwarz (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
ย 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
ย 
Folding Cheat Sheet #3 - third in a series
Folding Cheat Sheet #3 - third in a seriesFolding Cheat Sheet #3 - third in a series
Folding Cheat Sheet #3 - third in a series
ย 
Folding Cheat Sheet #1 - first in a series
Folding Cheat Sheet #1 - first in a seriesFolding Cheat Sheet #1 - first in a series
Folding Cheat Sheet #1 - first in a series
ย 
Scala Left Fold Parallelisation - Three Approaches
Scala Left Fold Parallelisation- Three ApproachesScala Left Fold Parallelisation- Three Approaches
Scala Left Fold Parallelisation - Three Approaches
ย 
Tagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also ProgramsTagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also Programs
ย 
Fusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with ViewsFusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with Views
ย 
A sighting of traverse_ function in Practical FP in Scala
A sighting of traverse_ function in Practical FP in ScalaA sighting of traverse_ function in Practical FP in Scala
A sighting of traverse_ function in Practical FP in Scala
ย 
A sighting of traverseFilter and foldMap in Practical FP in Scala
A sighting of traverseFilter and foldMap in Practical FP in ScalaA sighting of traverseFilter and foldMap in Practical FP in Scala
A sighting of traverseFilter and foldMap in Practical FP in Scala
ย 
A sighting of sequence function in Practical FP in Scala
A sighting of sequence function in Practical FP in ScalaA sighting of sequence function in Practical FP in Scala
A sighting of sequence function in Practical FP in Scala
ย 
N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets Cats
ย 
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
ย 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
ย 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
ย 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
ย 
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
ย 
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
ย 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
ย 
Jordan Peterson - The pursuit of meaning and related ethical axioms
Jordan Peterson - The pursuit of meaning and related ethical axiomsJordan Peterson - The pursuit of meaning and related ethical axioms
Jordan Peterson - The pursuit of meaning and related ethical axioms
ย 
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
ย 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
ย 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
ย 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
ย 

Recently uploaded (20)

The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
ย 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
ย 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
ย 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
ย 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
ย 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
ย 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
ย 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
ย 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
ย 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
ย 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
ย 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
ย 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
ย 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
ย 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
ย 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
ย 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
ย 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
ย 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
ย 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
ย 

Folding Cheat Sheet #2 - second in a series

  • 1. CHEAT-SHEET Folding #2 โˆถ / ๐’‚๐ŸŽ โˆถ / ๐’‚๐Ÿ โˆถ / ๐’‚๐Ÿ โˆถ / ๐’‚๐Ÿ‘ ๐’‡ / ๐’‚๐ŸŽ ๐’‡ / ๐’‚๐Ÿ ๐’‡ / ๐’‚๐Ÿ ๐’‡ / ๐’‚๐Ÿ‘ ๐’† @philip_schwarz slides by https://fpilluminated.com/
  • 2. โˆถ / ๐‘Ž0 โˆถ / ๐‘Ž1 โˆถ / ๐‘Ž2 โˆถ / ๐‘Ž3 ๐‘“ / ๐‘“ ๐‘Ž3 / ๐‘“ ๐‘Ž2 / ๐‘“ ๐‘Ž1 / ๐‘ ๐‘Ž0 ๐‘“ / ๐‘Ž0 ๐‘“ / ๐‘Ž1 ๐‘“ / ๐‘Ž2 ๐‘“ / ๐‘Ž3 ๐‘ ๐‘Ž0: (๐‘Ž1: ๐‘Ž2: ๐‘Ž3: ) ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3 var ๐‘Ž๐‘๐‘ = ๐‘ foreach(๐‘Ž in ๐‘Ž๐‘ ) ๐‘Ž๐‘๐‘ = ๐‘“(๐‘Ž๐‘๐‘, ๐‘Ž) return ๐‘Ž๐‘๐‘ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘Ž๐‘  ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ ๐‘Ž๐‘  ๐‘Ž๐‘  = [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ โˆท ๐›ผ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ = ๐‘ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘ฅ: ๐‘ฅ๐‘  = ๐‘“ ๐‘ฅ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ ๐‘ฅ๐‘  ๐‘“๐‘œ๐‘™๐‘‘๐‘™ โˆท ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ โ†’ ๐›ฝ โ†’ ๐›ผ โ†’ ๐›ฝ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ = ๐‘ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ ๐‘ฅ: ๐‘ฅ๐‘  = ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘ ๐‘ฅ ๐‘ฅ๐‘  ๐‘Ÿ๐‘’๐‘๐‘™๐‘Ž๐‘๐‘’: โˆถ ๐‘ค๐‘–๐‘กโ„Ž ๐‘“ ๐‘ค๐‘–๐‘กโ„Ž ๐‘ ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“ ๐‘Ž0 ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž2, ๐‘Ž3])) ๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [๐‘Ž3]))) ๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 (๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘“ ๐‘ [ ])))) ๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 ๐‘))) ๐‘“ ๐‘Ž0 (๐‘“ ๐‘Ž1 (๐‘“ ๐‘Ž2 (๐‘“ ๐‘Ž3 ๐‘))) ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘ [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 [๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 [๐‘Ž2, ๐‘Ž3] ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 [๐‘Ž3] ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3 [ ] ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘ ๐‘Ž0 ๐‘Ž1 ๐‘Ž2 ๐‘Ž3 Programmatic definition of right fold and left fold ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ associates ๐‘“ from the right ๐‘“๐‘œ๐‘™๐‘‘๐‘™ associates ๐‘“ from the left
  • 3. โˆถ / ๐‘Ž0 โˆถ / ๐‘Ž1 โˆถ / ๐‘Ž2 โˆถ / ๐‘Ž3 ๐‘“ / ๐‘“ ๐‘Ž3 / ๐‘“ ๐‘Ž2 / ๐‘“ ๐‘Ž1 / ๐‘ ๐‘Ž0 ๐‘“ / ๐‘Ž0 ๐‘“ / ๐‘Ž1 ๐‘“ / ๐‘Ž2 ๐‘“ / ๐‘Ž3 ๐‘ ๐‘Ž0: (๐‘Ž1: ๐‘Ž2: ๐‘Ž3: ) ๐‘“(๐‘“ ๐‘“ ๐‘“ ๐‘, ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3) ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘Ž๐‘  ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž๐‘  ๐‘Ž๐‘  = [๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3] ๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘)))) ๐‘“๐‘œ๐‘™๐‘‘๐‘™ = ๐‘; ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘ฅ๐‘  โงบ [๐‘ฅ] = ๐‘“(๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘ฅ๐‘  , ๐‘ฅ) ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ = ๐‘; ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ ๐‘ฅ โงบ ๐‘ฅ๐‘  = ๐‘“(๐‘ฅ, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ(๐‘ฅ๐‘ )) ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3 , ๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0, ๐‘Ž1, ๐‘Ž2 , ๐‘Ž3 ๐‘“(๐‘“(๐‘“๐‘œ๐‘™๐‘‘๐‘™ [๐‘Ž0, ๐‘Ž1] , ๐‘Ž2), ๐‘Ž3) ๐‘“ ๐‘“ ๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3 ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘“๐‘œ๐‘™๐‘‘๐‘™ [ ] , ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3 ๐‘“ ๐‘“ ๐‘“ ๐‘“ ๐‘, ๐‘Ž0 , ๐‘Ž1 , ๐‘Ž2 , ๐‘Ž3 ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž0, ๐‘Ž1, ๐‘Ž2, ๐‘Ž3]) ๐‘“(๐‘Ž0, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž1, ๐‘Ž2, ๐‘Ž3])) ๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž2, ๐‘Ž3]))) ๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([๐‘Ž3])))) ๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ([]))))) ๐‘“(๐‘Ž0, ๐‘“(๐‘Ž1, ๐‘“(๐‘Ž2, ๐‘“(๐‘Ž3, ๐‘)))) Mathematical definition of right fold and left fold ๐‘“๐‘œ๐‘™๐‘‘๐‘Ÿ associates ๐‘“ from the right ๐‘“๐‘œ๐‘™๐‘‘๐‘™ associates ๐‘“ from the left ๐‘ฅ = the Birst element ๐‘ฅs = all but the Birst element ๐‘ฅ = the last element ๐‘ฅ๐‘  = all but the last element