Download - 10 good reasons to invest your time in FP
#10 good reasons to invest your time in FP
Humberto Streb @humbertostreb
Joel Corrêa @joelcorrea_
#1 Learn
#2 Parallel collections
Multicore powered Parallel collections
F#
Collection operations: Map - Reduce
Map –> Applies a given fn to each element
Reduce –> Combine / Accumulate /
fold / compress results though combining operation
Higher order functions
Sample
Map
20 18 41 25 29 32 30 38
age
Map
Reduce
20 18
236
25 44 29 32 …
Combining fn: a+b (operation = +)
+ Data
Map age Map age Map age Map age
map in parallel
reduce in parallel
filter in parallel
#3 Focus
Boilerplate code
REPL
#4 Troubleshooting
Same result value given the same
arguments
Troubleshooting in FP
Consistency
Once wrong, always wrong
Arguments only
No global state
Referential transparency
#5 State discipline
Side effects…
Pure function
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
Immutable
Immutable
#6 Built-ins
Non-Blocking
Futures
Parallel
Null checks
Optionals
Explicit
Interoperability
#8 Simplicity
#7 Simplicity
#8 Simplicity
Salesmen…
#8 Simplicity
#8 Composition
# Building blocks
Inheritance
Polymorphism
HOFs
Composition
OOP = Objects
FP = Functions
Real world / Complex scenarios
# HOFs
Receives fn
# Partially applied
Returns fn
# Composition
#9 Testability
if($player->getScore() > 0) {!!$player->setSwizzle(7);!
} else {!!$player->setSwizzle(!! !$player->getSwizzle() + 1;!!);!
}!
Hard to test
#10 Principles
FP in non-FP languages
Guidelines
Side effects
Immutability
Referen'al transparency
FP in non-FP languages
functools
LuaFun
# Challenges ahead
Readability / Expressiveness
Learning curve
Samples
https://github.com/jjcorrea/TenGoodReasonsToInvestYourTimeInFP
Resources
http://twitter.github.io/scala_school/ http://twitter.github.io/effectivescala http://coursera.org/course/progfun