Page 1
Intro to scala
Ignasi Marimon-Clos (@ignasi35)
IronHack
Page 3
@ignasi35
about you
Page 4
@ignasi35
about me
@ignasi35
1) problem solver, Garbage Collector, scala, java8
2) kayaker
3) under construction
4) all things JVM
Page 6
@ignasi35
ruby vs scala
more similar than you think
Page 7
@ignasi35
ruby vs scala
√ Lambda + closures + currying
√ Collection manipulation (via lambdas)
√ traits (similar to modules)
√ No monkey patching
Page 8
@ignasi35
ruby vs scala
https://twitter.com/raichoo/status/692089108022312960
Page 9
@ignasi35
mri v jvm
http://www.slideshare.net/CharlesNutter/over-9000-jruby-in-2015
Page 10
@ignasi35
mri v jvm
http://www.slideshare.net/CharlesNutter/over-9000-jruby-in-2015
Page 11
@ignasi35
mri v jvm
http://jruby.org/bench9000/
Page 12
@ignasi35
mri v jvm
http://jruby.org/bench9000/
Page 13
@ignasi35
also: invoke scala from ruby !!
mri v jvm
Page 14
@ignasi35
teh codez
source code
Page 15
@ignasi35
teh codez
https://gist.github.com/ignasi35/65f729a9a65aa6296933b100026a0fa1source code
Page 16
@ignasi35 End of presentation
Page 30
@ignasi35
Types
class PersonBuilder {
Person build(String name, String surname) { … }
}
Page 33
@ignasi35
Types
class PersonBuilder {
Person build(Name name, Surname surname) { … }
}
Page 36
@ignasi35
Case Classes
Page 37
@ignasi35
Case Classes
Equality
Copy
Pattern Matching
Immutable
Syntactic Sugar
Page 39
@ignasi35
Case Classes
Equality
Copy
Pattern Matching
Immutable
Syntactic Sugar
º
Page 46
@ignasi35
Func Prog
Pure Functions
no side effects
if not used, remove it
fixed in — fixed out
Page 47
@ignasi35
filter
f
Page 49
@ignasi35
fold
f
f
f
Page 50
@ignasi35
fold
aka reduce
Page 51
@ignasi35
map revisited
f
Page 52
@ignasi35
f
map revisited
Page 54
@ignasi35
flatMap
f
Page 57
@ignasi35
recap
filter
map
fold
flatMap
Page 60
@ignasi35
Null Dealing
Page 62
@ignasi35
Null Dealing
class PersonBuilder {
Person build(Name name, Option[Surname] surname) { … }
}
Page 63
@ignasi35
Maybe (aka Option)
replaces null completely
Page 64
@ignasi35
Maybe (aka Option)
replaces null completelyforever
Page 65
@ignasi35
Maybe (aka Option)
replaces null completelyforever
and ever
Page 66
@ignasi35
Maybe (aka Option)
replaces null completelyforever
and everand ever
Page 67
@ignasi35
Maybe (aka Option)
replaces null completelyforever
and everand everand ever
Page 68
@ignasi35
Maybe (aka Option)
replaces null completelyforever
and everand everand everand ever
Page 69
@ignasi35
Maybe (aka Option)
replaces null completelyforever
and everand everand everand everand ever
Page 70
@ignasi35
filter
f f f
Page 71
@ignasi35
map
f f
Page 72
@ignasi35
fold
f f
Page 73
@ignasi35
Maybe (aka Option)
filter: applies predicate and Returns input or Nonemap: converts contentfold: returns Some(content) or Some(zero)flatMap: see list
get: returns content or throws ExceptiongetOrElse: returns content or defaultValue
Page 74
@ignasi35
recap
filter
map
fold
flatMap
Page 84
@ignasi35
W T F ! ? ! ?
Page 87
@ignasi35
railway programming
https://fsharpforfunandprofit.com/posts/recipe-part2/
Page 88
@ignasi35
INPUT
FAILURE SUCCESS
Page 89
@ignasi35
REQUEST
401
RESPONSE
404
400
Page 91
@ignasi35
railway programming
Page 93
@ignasi35
Live Live coding
Page 94
@ignasi35
Conclusions
Page 96
@ignasi35
Conclusions
Read books
Page 97
@ignasi35
Conclusions
Read teh bookz ! ! !
Page 98
@ignasi35
Conclusions
because there’s no
One Tool To Rule Them All
Page 99
@ignasi35
Conclusions
Use Types
Page 100
@ignasi35
Conclusions
and immutabilty
Page 101
@ignasi35
Conclusions
prepare for failures
Page 102
@ignasi35
Conclusions
but don’t let it clutter your code
Page 112
@ignasi35
Arigató
Page 113
@ignasi35
Questions
Page 114
@ignasi35End of presentation