Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Próxima SlideShare
Cargando en…5
×

# Functional programming in scala

1.884 visualizaciones

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Sé el primero en comentar

### Functional programming in scala

1. 1. FP in Scala Enero 2015
2. 2. WHY FP? • FP Concepts • FP “powers” 1 2 3FP IN SCALA: THE BASICS • Mutability vs Immutability • HOFs • Functions = First-class citizens FP TOOLS • For-comprehension (desugaring) • Try & Either ÍNDICE
3. 3. WHY FP? 1
4. 4. Functional Programming in Scala 1.1 FP Concepts: Pure Function A function of type A => B maps every value of type A to exactly one value of type B And does nothing else “Nothing else” = Side effects: Modifying a data structure, setting a field on a object, throwing an exception, printing to the console, reading from or writing to a file 1 WHY FP?
5. 5. Functional Programming in Scala 1.1 FP Concepts: Referential transparency 1 WHY FP? If you have an expression, this expression is RT if you can evaluate it and then replace this expression with the value that you get A function is pure if f(x) is RT when x is RT
6. 6. Functional Programming in Scala 1.1 FP Concepts: Scala is not a purely functional language!! 1 WHY FP?
7. 7. Functional Programming in Scala 1.2 FP “Powers”: Testability 1 WHY FP?
8. 8. Functional Programming in Scala 1.2 FP “Powers”: Testability 1 WHY FP?
9. 9. Functional Programming in Scala 1.2 FP “Powers”: Testability 1 WHY FP?
10. 10. Functional Programming in Scala 1.2 FP “Powers”: Testability 1 WHY FP?
11. 11. Functional Programming in Scala 1.2 FP “Powers”: Reusability 1 WHY FP?
12. 12. Functional Programming in Scala 1.2 FP “Powers”: Reusability 1 WHY FP?
13. 13. Functional Programming in Scala 1.2 FP “Powers”: Reusability 1 WHY FP?
14. 14. Functional Programming in Scala 1.2 FP “Powers”: Reusability 1 WHY FP?
15. 15. Functional Programming in Scala 1.2 FP “Powers”: Reusability 1 WHY FP?
16. 16. Functional Programming in Scala 1.2 FP “Powers”: Parallelizability 1 WHY FP?
17. 17. Functional Programming in Scala 1.2 FP “Powers”: Comprehension 1 WHY FP?
18. 18. FP IN SCALA: THE BASICS2
19. 19. Functional Programming in Scala 2.1 Mutability vs Immutability 2 FP IN SCALA: THE BASICS
20. 20. Functional Programming in Scala 2.1 Mutability vs Immutability 2 FP IN SCALA: THE BASICS
21. 21. Functional Programming in Scala 2.1 Mutability vs Immutability 2 FP IN SCALA: THE BASICS
22. 22. Functional Programming in Scala 2.1 Mutability vs Immutability 2 FP IN SCALA: THE BASICS All the classes that mix-in this trait should be in this file A is covariant
23. 23. Functional Programming in Scala 2.1 Mutability vs Immutability 2 FP IN SCALA: THE BASICS Variadic function syntax Tail call annotation
24. 24. Functional Programming in Scala 2.2 Higher Order Functions 2 FP IN SCALA: THE BASICS
25. 25. Functional Programming in Scala 2.3 Functions = First-class citizens 2 FP IN SCALA: THE BASICS Method Function
26. 26. Functional Programming in Scala 2.3 Functions = First-class citizens 2 FP IN SCALA: THE BASICS Function literal Function value
27. 27. FP TOOLS 3
28. 28. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
29. 29. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
30. 30. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
31. 31. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
32. 32. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
33. 33. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
34. 34. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS flatMap
35. 35. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS http://docs.scala-lang.org/tutorials/FAQ/yield.html
36. 36. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
37. 37. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
38. 38. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
39. 39. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS
40. 40. Functional Programming in Scala 3.1 For-comprehension 3 FP TOOLS What else?? Monads!!! Future Try Iteratee RDD (warning!) ...
41. 41. Functional Programming in Scala 3.2 Try & Either 3 FP TOOLS Alternatives to “pure” exceptions Why? 1º. Exceptions break RT 2º. Exceptions are NOT type-safe
42. 42. Functional Programming in Scala 3.2 Try & Either 3 FP TOOLS
43. 43. Functional Programming in Scala 3.2 Try & Either 3 FP TOOLS //Awesome Dataviiiiiis code ;)
44. 44. Functional Programming in Scala 3.2 Try & Either 3 FP TOOLS //Awesome Dataviiiiiis code ;)
45. 45. Functional Programming in Scala 3.2 Try & Either 3 FP TOOLS
46. 46. Functional Programming in Scala
47. 47. Functional Programming in Scala Functional way “powers” => Testability, Reusability, Parallelizability, Comprehension Immutability & HOFs For-comprehension => map, flatMap, filter Functional way => Handling exceptions