Slide 1

Slide 1 text

Scala Functional Programming Combinators Code Kata start with expression ma flatMap f and keep refactoring it by applying each of ⑧ rewrite rules in turn until you get back to ma flatMap f @philip_schwarz slides by https://www.slideshare.net/pjschwarz

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Rewrite Rules ① flatmap can be defined in terms of map and flatten ② map can be defined in terms of flatMap and pure ③ flatten can be defined in terms of flatMap and identity ④ chained flatMaps are equivalent to nested flatMaps (flatMap associativity law) ⑤ Kleisli composition can be defined in terms of flatMap (apply this the other way around) ⑥ the identity function can be defined in terms of flatten and pure ⑦ pure followed by flatten cancel each other out ⑧ pure is the identity function for Kleisli composition, so f >=> pure is the same as f

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Only half-serious, of course. But you may find it useful to work through the refactorings to improve your understanding of various combinators. And if you can’t be asked to type it all out, I made a gist for you @philip_schwarz https://gist.github.com/philipschwarz/a677eaa7ccc87d54673226f307b3fdb5