114
Intro to scala Ignasi Marimon-Clos (@ignasi35) IronHack

Intro scala for rubyists (ironhack)

Embed Size (px)

Citation preview

Intro to scala

Ignasi Marimon-Clos (@ignasi35)

IronHack

@ignasi35

thanks!

@ignasi35

about you

@ignasi35

about me

@ignasi35

1) problem solver, Garbage Collector, scala, java8

2) kayaker

3) under construction

4) all things JVM

@ignasi35

@ignasi35

ruby vs scala

more similar than you think

@ignasi35

ruby vs scala

√ Lambda + closures + currying

√ Collection manipulation (via lambdas)

√ traits (similar to modules)

√ No monkey patching

@ignasi35

ruby vs scala

https://twitter.com/raichoo/status/692089108022312960

@ignasi35

mri v jvm

http://www.slideshare.net/CharlesNutter/over-9000-jruby-in-2015

@ignasi35

mri v jvm

http://www.slideshare.net/CharlesNutter/over-9000-jruby-in-2015

@ignasi35

mri v jvm

http://jruby.org/bench9000/

@ignasi35

mri v jvm

http://jruby.org/bench9000/

@ignasi35

also: invoke scala from ruby !!

mri v jvm

@ignasi35 End of presentation

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

Types

class PersonBuilder {

Person build(String name, String surname) { … }

}

@ignasi35

@ignasi35

@ignasi35

Types

class PersonBuilder {

Person build(Name name, Surname surname) { … }

}

@ignasi35

@ignasi35

@ignasi35

Case Classes

@ignasi35

Case Classes

Equality

Copy

Pattern Matching

Immutable

Syntactic Sugar

@ignasi35

@ignasi35

Case Classes

Equality

Copy

Pattern Matching

Immutable

Syntactic Sugar

º

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

Func Prog

Pure Functions

no side effects

if not used, remove it

fixed in — fixed out

@ignasi35

filter

f

@ignasi35

map

f

@ignasi35

fold

f

f

f

@ignasi35

fold

aka reduce

@ignasi35

map revisited

f

@ignasi35

f

map revisited

@ignasi35

map

f

@ignasi35

flatMap

f

@ignasi35

@ignasi35

@ignasi35

recap

filter

map

fold

flatMap

@ignasi35

@ignasi35

@ignasi35

Null Dealing

@ignasi35

@ignasi35

Null Dealing

class PersonBuilder {

Person build(Name name, Option[Surname] surname) { … }

}

@ignasi35

Maybe (aka Option)

replaces null completely

@ignasi35

Maybe (aka Option)

replaces null completelyforever

@ignasi35

Maybe (aka Option)

replaces null completelyforever

and ever

@ignasi35

Maybe (aka Option)

replaces null completelyforever

and everand ever

@ignasi35

Maybe (aka Option)

replaces null completelyforever

and everand everand ever

@ignasi35

Maybe (aka Option)

replaces null completelyforever

and everand everand everand ever

@ignasi35

Maybe (aka Option)

replaces null completelyforever

and everand everand everand everand ever

@ignasi35

filter

f f f

@ignasi35

map

f f

@ignasi35

fold

f f

@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

@ignasi35

recap

filter

map

fold

flatMap

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

W T F ! ? ! ?

@ignasi35

@ignasi35

@ignasi35

railway programming

https://fsharpforfunandprofit.com/posts/recipe-part2/

@ignasi35

INPUT

FAILURE SUCCESS

@ignasi35

REQUEST

401

RESPONSE

404

400

@ignasi35

@ignasi35

railway programming

@ignasi35

@ignasi35

Live Live coding

@ignasi35

Conclusions

@ignasi35

@ignasi35

Conclusions

Read books

@ignasi35

Conclusions

Read teh bookz ! ! !

@ignasi35

Conclusions

because there’s no

One Tool To Rule Them All

@ignasi35

Conclusions

Use Types

@ignasi35

Conclusions

and immutabilty

@ignasi35

Conclusions

prepare for failures

@ignasi35

Conclusions

but don’t let it clutter your code

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

@ignasi35

Arigató

@ignasi35

Questions

@ignasi35End of presentation