Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
×

The hidden mystery behind Scala functional programming

1,279 views

Published on

In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

Published in: Software
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

The hidden mystery behind Scala functional programming

1. 1. Harmeet Singh (Taara) Sr. Software Consultant http://harmeetsingh.in/
2. 2. Agenda ✔ Functional Programming ✔ Functional Programming ✔ Functional Programming
3. 3. Back2Basics Albert Einstein had to essentially go back to school and learn a lot of math so he could turn the Theory of Special Relativity into the Theory of General Relativity.
4. 4. Functional Programming Runar Bjarnason
5. 5. Functional Programming What is Pure Function means???
6. 6. Functional Programming Pure Function is not About first-class functions Or higher-order procedures
7. 7. Functional Programming Functional Programming is not about immutability
8. 8. Functional Programming Functional Programming is Programming with pure functions
9. 9. Functional Programming: Advantages ✔ Readability. ✔ Easy testing. ✔ Easy debugging. ✔ Meaningful signatures. ✔ Easy parallel-programming. and more...
10. 10. Functional Programming: Disadvantages ✔ Difficult to combine. ✔ Math terminology (monads, monoids etc). ✔ Recursion doesn't feel natural. ✔ Only immutable ✔ IO and others and more...
11. 11. Functional Programming: Algebra // Algebra f(x) = x + 1 f(x,y) = x + y f(a,b,c,x) = a * x^2 + b*x + c // Scala code def f(x: Int) = x + 1 def f(x: Int, y: Int) = x + y def f(a: Int, b: Int, c: Int, x: Int) =  a*x*x + b*x + c
12. 12. Functional Programming: Algebra val b = f(a) val c = g(b) Val d = h(c) val result = x + y + z PureFunctions+ ImmutableValues== Algebra
13. 13. Functional Programming: HOF Class SomeType { def map(f: A => B): SomeType[B] { … } def flatMap(f: A => SomeType[B]): SomeType[B] { … } }
14. 14. Functional Programming
15. 15. Functional Programming DEMO
16. 16. Functional Programming: For Expression Monadic Operator ( ← )
17. 17. Functional Programming: For Expression
18. 18. References: ✔ https://www.infoq.com/presentations/io-functional-side-effects ✔ https://alvinalexander.com/scala/examples-shows-differences-between-strict ✔ https://stackoverflow.com/questions/19617378/withfilter-instead-of-filter ✔ https://alvinalexander.com/scala/fp-book/how-enable-filtering-class-in-for-exp ✔ http://docs.scala-lang.org/tutorials/FAQ/yield.html ✔ https://alvinalexander.com/downloads/learning-fp-in-scala-0.1.1.pdf