SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie Folding Cheat Sheet #2 - second in a series

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 iiWilber Acharte Prado
 
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 3Yosia Adi Setiawan
 
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 iiWilber Acharte Prado
 
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 3Yosia Adi Setiawan
 
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 inersiabisma 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 inersiabisma samudra
 
Θεωρία - Ορισμοί - Προτάσεις 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 ccesa007Demetrio 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 ccesa007Demetrio Ccesa Rayme
 
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).pptxtungwc
 
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).pptxtungwc
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine LearningSEMINARGROOT
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine LearningSEMINARGROOT
 

Ähnlich wie Folding Cheat Sheet #2 - second in a series (20)

Backpropagation
BackpropagationBackpropagation
Backpropagation
 
Backpropagation
BackpropagationBackpropagation
Backpropagation
 
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
 

Mehr von Philip Schwarz

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 seriesPhilip Schwarz
 
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 seriesPhilip Schwarz
 
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 seriesPhilip Schwarz
 
Scala Left Fold Parallelisation - Three Approaches
Scala Left Fold Parallelisation- Three ApproachesScala Left Fold Parallelisation- Three Approaches
Scala Left Fold Parallelisation - Three ApproachesPhilip Schwarz
 
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 ProgramsPhilip Schwarz
 
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 ViewsPhilip Schwarz
 
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 ScalaPhilip Schwarz
 
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 ScalaPhilip Schwarz
 
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 ScalaPhilip Schwarz
 
N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsPhilip Schwarz
 
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...Philip Schwarz
 
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...Philip Schwarz
 
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 examplePhilip Schwarz
 
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 examplePhilip Schwarz
 
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...Philip Schwarz
 
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...Philip Schwarz
 
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...Philip Schwarz
 
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 axiomsPhilip Schwarz
 
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...Philip Schwarz
 
Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...Philip Schwarz
 

Mehr von Philip Schwarz (20)

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...
 
Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...
 

Kürzlich hochgeladen

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Kürzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.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