SlideShare une entreprise Scribd logo
1  sur  4
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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 (...
 

Dernier

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
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.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
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
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
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
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Dernier (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
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 ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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 ...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
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
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
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
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

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