10 good reasons to invest your time in fp
DESCRIPTION
http://www.thedevelopersconference.com.br/tdc/2014/portoalegre/trilha-linguagens-funcionaisTRANSCRIPT
![Page 1: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/1.jpg)
#10 good reasons to invest your time in FP
Humberto Streb @humbertostreb
Joel Corrêa @joelcorrea_
![Page 2: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/2.jpg)
![Page 3: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/3.jpg)
#1 Learn
![Page 4: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/4.jpg)
![Page 5: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/5.jpg)
#2 Parallel collections
![Page 6: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/6.jpg)
Multicore powered Parallel collections
F#
![Page 7: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/7.jpg)
Collection operations: Map - Reduce
![Page 8: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/8.jpg)
Map –> Applies a given fn to each element
Reduce –> Combine / Accumulate /
fold / compress results though combining operation
Higher order functions
![Page 9: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/9.jpg)
Sample
![Page 10: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/10.jpg)
Map
20 18 41 25 29 32 30 38
age
Map
![Page 11: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/11.jpg)
Reduce
20 18
236
25 44 29 32 …
Combining fn: a+b (operation = +)
![Page 12: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/12.jpg)
+ Data
Map age Map age Map age Map age
![Page 13: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/13.jpg)
map in parallel
![Page 14: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/14.jpg)
reduce in parallel
![Page 15: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/15.jpg)
filter in parallel
![Page 16: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/16.jpg)
#3 Focus
![Page 17: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/17.jpg)
Boilerplate code
![Page 18: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/18.jpg)
![Page 19: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/19.jpg)
![Page 20: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/20.jpg)
REPL
![Page 21: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/21.jpg)
#4 Troubleshooting
![Page 22: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/22.jpg)
Same result value given the same
arguments
![Page 23: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/23.jpg)
Troubleshooting in FP
Consistency
Once wrong, always wrong
Arguments only
No global state
Referential transparency
![Page 24: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/24.jpg)
#5 State discipline
![Page 25: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/25.jpg)
Side effects…
![Page 26: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/26.jpg)
Pure function
![Page 27: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/27.jpg)
Immutable It is highly recommended that value objects be immutable. They are created with a constructor, and never modified during their life time. Eric Evans
![Page 28: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/28.jpg)
Immutable
![Page 29: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/29.jpg)
Immutable
![Page 30: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/30.jpg)
#6 Built-ins
![Page 31: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/31.jpg)
Non-Blocking
Futures
Parallel
![Page 32: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/32.jpg)
Null checks
Optionals
Explicit
![Page 33: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/33.jpg)
Interoperability
![Page 34: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/34.jpg)
#8 Simplicity
#7 Simplicity
![Page 35: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/35.jpg)
![Page 36: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/36.jpg)
#8 Simplicity
Salesmen…
![Page 37: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/37.jpg)
#8 Simplicity
![Page 38: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/38.jpg)
#8 Composition
![Page 39: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/39.jpg)
# Building blocks
Inheritance
Polymorphism
HOFs
Composition
OOP = Objects
FP = Functions
Real world / Complex scenarios
![Page 40: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/40.jpg)
# HOFs
Receives fn
![Page 41: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/41.jpg)
# Partially applied
Returns fn
![Page 42: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/42.jpg)
# Composition
![Page 43: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/43.jpg)
#9 Testability
![Page 44: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/44.jpg)
if($player->getScore() > 0) {!!$player->setSwizzle(7);!
} else {!!$player->setSwizzle(!! !$player->getSwizzle() + 1;!!);!
}!
Hard to test
![Page 45: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/45.jpg)
![Page 46: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/46.jpg)
![Page 47: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/47.jpg)
#10 Principles
![Page 48: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/48.jpg)
FP in non-FP languages
Guidelines
Side effects
Immutability
Referen'al transparency
![Page 49: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/49.jpg)
FP in non-FP languages
functools
LuaFun
![Page 50: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/50.jpg)
# Challenges ahead
![Page 51: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/51.jpg)
Readability / Expressiveness
![Page 52: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/52.jpg)
Learning curve
![Page 53: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/53.jpg)
![Page 54: 10 good reasons to invest your time in FP](https://reader033.vdocuments.site/reader033/viewer/2022060119/558def061a28ab2b7e8b4695/html5/thumbnails/54.jpg)
Samples
https://github.com/jjcorrea/TenGoodReasonsToInvestYourTimeInFP
Resources
http://twitter.github.io/scala_school/ http://twitter.github.io/effectivescala http://coursera.org/course/progfun