types working for you - qconlondon.com€¦ · part 1 straightforward scala part 2 functional...
TRANSCRIPT
![Page 1: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/1.jpg)
Types Working For You
Richard Dallaway, @d6y
underscore.io
![Page 2: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/2.jpg)
Modern type system with lots of power
![Page 3: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/3.jpg)
![Page 4: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/4.jpg)
![Page 5: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/5.jpg)
Two Themes
Straightforward Scala
Types Working for Us
![Page 6: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/6.jpg)
Progression
Part 1 Straightforward Scala
Part 2 Functional Programming
Part 3 Typelevel Programming
![Page 7: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/7.jpg)
Straightforward Scala
— Part 1 —
![Page 8: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/8.jpg)
The only problem was we had no idea what the code was doing at first.
We came across a strange symbol we hadn’t seen in our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
![Page 9: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/9.jpg)
The only problem was we had no idea what the code was doing at first.
We came across a strange symbol we hadn’t seen in our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
![Page 10: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/10.jpg)
The only problem was we had no idea what the code was doing at first.
We came across a strange symbol we hadn’t seen in our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
![Page 11: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/11.jpg)
The only problem was we had no idea what the code was doing at first.
We came across a strange symbol we hadn’t seen in our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
![Page 12: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/12.jpg)
“It’s about having a maintainable code base where you can have people cross projects easily and get new hires up to speed rapidly”
![Page 13: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/13.jpg)
Power!
Protect the team from it
and
Get the benefit of it
![Page 14: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/14.jpg)
What can we do?
![Page 15: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/15.jpg)
1. Expressions, types, & values
2. Objects and classes
3. Algebraic data types
4. Structural recursion
5. Sequencing computation
6. Type classes
![Page 16: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/16.jpg)
1. Expressions, types, & values
2. Objects and classes
3. Algebraic data types
4. Structural recursion
5. Sequencing computation
6. Type classes
![Page 17: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/17.jpg)
Algebraic data types
Structural recursion
![Page 18: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/18.jpg)
Algebraic data types data into code
Structural recursion
transformation
![Page 19: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/19.jpg)
Model data with logical ors and logical ands
![Page 20: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/20.jpg)
A website visitor is: • anonymous; or • logged in
![Page 21: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/21.jpg)
A logged in user has: • an ID; and • facts we know about
them
![Page 22: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/22.jpg)
Two Patterns
and (product types) or (sum types)
Sum and product together make algebraic data types
![Page 23: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/23.jpg)
Structure of the code follows the structure of
the data
![Page 24: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/24.jpg)
A website visitor is: • anonymous; or • logged in
![Page 25: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/25.jpg)
sealed trait Visitor
case class Anonymous() extends Visitor
case class User() extends Visitor
![Page 26: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/26.jpg)
A logged in user has: • an ID; and • facts we know about
them
An anonymous has: • an ID
![Page 27: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/27.jpg)
sealed trait Visitor
case class Anonymous() extends Visitor
case class User() extends Visitor
![Page 28: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/28.jpg)
sealed trait Visitor
case class Anonymous(id: Id) extends Visitor
case class User(id: Id, facts: Set[Fact]) extends Visitor
![Page 29: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/29.jpg)
Structural recursion
![Page 30: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/30.jpg)
def serveAd(v: Visitor): Advert = ???
![Page 31: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/31.jpg)
Structure of the code follows the structure of
the data
![Page 32: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/32.jpg)
def serveAd(v: Visitor): Advert = ???
![Page 33: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/33.jpg)
def serveAd(v: Visitor): Advert = v match { case User(_, info) => relevantAd(info) case Anonymous(id) => adRotation(id) }
![Page 34: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/34.jpg)
def serveAd(v: Visitor): Advert = v match { case User(_, info) => relevantAd(info) case Anonymous(id) => adRotation(id) }
![Page 35: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/35.jpg)
def serveAd(v: Visitor): Advert = v match { case User(_, info) => relevantAd(info) case Anonymous(id) => adRotation(id) }
Structure
![Page 36: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/36.jpg)
ADT & Structural Recursion
Straightforward part of Scala.
Clear, productive, occurs frequently.
Be opinionated in what you use.
Structure helps us.
![Page 37: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/37.jpg)
Help from FP Ideas
— Part 2 —
![Page 38: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/38.jpg)
Combining lists
Concatenating strings
Union of sets
Combining things in a loop
Chaining logical operations
Adding numbers
Building up a JavaScript expression
Showing errors in a UI
...
![Page 39: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/39.jpg)
A combine function and
an empty value
![Page 40: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/40.jpg)
Addition
Empty Combine
0 +
![Page 41: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/41.jpg)
Set
Empty Combine
Set.empty union
![Page 42: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/42.jpg)
For any T
Empty Combine
A zero for T
A way to combine two Ts
and give me back a T
![Page 43: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/43.jpg)
A combine function and
an empty value
![Page 44: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/44.jpg)
Monoid
A combine function and
an empty value
…and laws
![Page 45: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/45.jpg)
![Page 46: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/46.jpg)
The boss asks…
What’s the total visits to the web site?
def report(vs: List[Int]): Int = ???
![Page 47: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/47.jpg)
For any T
Empty Combine
A zero for T
A way to combine two Ts
and give me back a T
![Page 48: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/48.jpg)
For any T
trait Monoid[T] {
def empty: T
def combine(x: T, y: T): T
}
![Page 49: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/49.jpg)
val addition = new Monoid[Int] {
def empty = 0
def combine(x: Int, y: Int) = x+y
}
![Page 50: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/50.jpg)
fold
![Page 51: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/51.jpg)
def fold(vs: List[Int]): Int =
vs match {
case Nil => 0
case v :: rest => v + fold(rest)
}
fold(List(1,2,3)) // 6
![Page 52: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/52.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 53: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/53.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 54: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/54.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 55: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/55.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 56: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/56.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 57: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/57.jpg)
fold(1,2,3)
1 + fold(2,3)
2 + fold(3)
3 + fold()
0
0 + 3 + 2 + 1 = 6
![Page 58: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/58.jpg)
def fold(vs: List[Int]): Int =
vs match {
case Nil => 0
case v :: rest => v + fold(rest)
}
fold(List(1,2,3)) // 6
![Page 59: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/59.jpg)
def fold(vs: List[Int], m: Monoid[Int]): Int =
vs match {
case Nil => 0
case v :: rest => v + fold(rest)
}
fold(List(1,2,3), addition) // 6
![Page 60: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/60.jpg)
def fold(vs: List[Int], m: Monoid[Int]): Int =
vs match {
case Nil => m.empty
case v :: rest => m.combine(v, fold(rest,m))
}
fold(List(1,2,3), addition) // 6
![Page 61: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/61.jpg)
def fold[T](vs: List[T], m: Monoid[T]): T =
vs match {
case Nil => m.empty
case v :: rest => m.combine(v, fold(rest,m))
}
fold(List(1,2,3), addition) // 6
![Page 62: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/62.jpg)
Split on cases,
inspect values you have
![Page 63: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/63.jpg)
def fold[T](vs: List[T], m: Monoid[T]): T =
vs match {
case Nil => ???
case v :: rest => ???
}
fold(List(1,2,3), addition) // 6
![Page 64: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/64.jpg)
def fold[T](vs: List[T], m: Monoid[T]): T =
vs match {
case Nil => m.empty
case v :: rest => ???
}
fold(List(1,2,3), addition) // 6
![Page 65: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/65.jpg)
But back to Monoids…
![Page 66: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/66.jpg)
The boss asks…
What’s the total visits to the web site?
def report(vs: List[Int]): Int =
fold(vs, addition)
![Page 67: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/67.jpg)
Benefits
Composition
Flexibility
Problem Solving
![Page 68: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/68.jpg)
The boss asks…
How many distinct visitors?
def report(vs: List[Visitor]): Int = ???
![Page 69: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/69.jpg)
Set
Empty Combine
Set.empty union
![Page 70: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/70.jpg)
The boss says…
Argh! The servers are OutOfMemory
![Page 71: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/71.jpg)
HyperLogLog
Empty Combine
new HLL() HLL.plus
Armon Dadgar (Papers We Love, 2015) “Bloom Filters and HyperLogLog”
![Page 72: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/72.jpg)
The boss asks…
Who are the really keen visitors to the site?
![Page 73: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/73.jpg)
Count-Min Sketch
Empty Combine
new CMS() CMS.plus
Laura Bledaite (Scala eXchange 2015) “Count-Min Sketch in Real Data Applications”
![Page 74: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/74.jpg)
We can safely run a parallel version
of fold
![Page 75: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/75.jpg)
Laws
![Page 76: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/76.jpg)
a + 0 = a
(a + b) + c = a + (b + c)
![Page 77: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/77.jpg)
Identity & Associativity
a combine empty = a
(a combine b) combine c = a combine (b combine c)
![Page 78: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/78.jpg)
a combine b
combine combine
c d e f
![Page 79: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/79.jpg)
![Page 80: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/80.jpg)
Errors: 10 Warnings: 0
![Page 81: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/81.jpg)
Its a monoid
I know this
![Page 82: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/82.jpg)
…so we fold
![Page 83: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/83.jpg)
Summary
Types and laws give us flexibility & help lead us to solutions.
They help us every day.
![Page 84: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/84.jpg)
A Taste of Typelevel
— Part 3 —
![Page 85: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/85.jpg)
Date Metric
Mon Low
Tue High
csv( List(“Date”, “Metric”), List( List(“Mon”, “Low”), List(“Tue”, “High”) ) )
![Page 86: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/86.jpg)
Date
Mon Low
Tue High
csv( List(“Date”), List( List(“Mon”, “Low”), List(“Tue”, “High”) ) )
![Page 87: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/87.jpg)
How can we prevent that error happening again?
![Page 88: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/88.jpg)
def csv( hdrs: List[String], rows: List[List[String]] ): String = ???
![Page 89: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/89.jpg)
def csv[N <: Nat]( hdrs: List[String], rows: List[List[String]] ): String = ???
import shapeless._ import syntax.sized._
![Page 90: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/90.jpg)
def csv[N <: Nat]( hdrs: Sized[List[String], N], rows: List[Sized[List[String], N]] ): String = ???
import shapeless._ import syntax.sized._
![Page 91: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/91.jpg)
csv( Sized(“Date”), List(
Sized(“Mon”, “Low”), Sized(“Tue”, “High”) )
)
![Page 92: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/92.jpg)
csv( Sized(“Date”), List(
Sized(“Mon”, “Low”), Sized(“Tue”, “High”) )
)
Sized[List, 1]
Sized[List, 2]
![Page 93: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/93.jpg)
How?
Sized(“Date”) constructs Sized[Nat]
Nat implements numbers as types
![Page 94: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/94.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat
![Page 95: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/95.jpg)
Zero 0 Succ[Zero] 1 Succ[Succ[Zero]] 2 Succ[Succ[Succ[Zero]]] 3
![Page 96: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/96.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat
![Page 97: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/97.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat type One = Succ[Zero] type Two = Succ[One]
implicitly[Succ[Zero] =:= One] implicitly[Succ[One] =:= Succ[Succ[Zero]]]
![Page 98: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/98.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat type One = Succ[Zero] type Two = Succ[One]
implicitly[Succ[Zero] =:= One] implicitly[Succ[One] =:= Succ[Succ[Zero]]]
![Page 99: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/99.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat type One = Succ[Zero] type Two = Succ[One]
implicitly[Succ[Zero] =:= One] implicitly[Succ[One] =:= Succ[Succ[Zero]]]
![Page 100: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/100.jpg)
sealed trait Nat trait Succ[P <: Nat] extends Nat trait Zero extends Nat type One = Succ[Zero] type Two = Succ[One]
implicitly[Succ[Zero] =:= Two] error: Cannot prove that Succ[Zero] =:= Two.
![Page 101: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/101.jpg)
Merging Fields
![Page 102: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/102.jpg)
case class User( id : Long, name : String, email : Option[String])
val user = User( 123L, “Bruce Wayne”, Some(“[email protected]”))
![Page 103: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/103.jpg)
PATCH /user/123
{ “name” : “Batman”}
![Page 104: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/104.jpg)
case class User( id : Long, name : String, email : Option[String])
case class Update( name : Option[String], email : Option[Option[String]])
![Page 105: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/105.jpg)
val user = User( 123L, “Bruce Wayne”, Some(“[email protected]”))
val update = Update( Some(“Batman”), None)
How do we get to…
User( 123L, “Batman”, Some(“[email protected]”))
![Page 106: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/106.jpg)
Bulletin
https://github.com/davegurnell/bulletin
![Page 107: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/107.jpg)
How?
User String Option[String] …
Option[String]Option[
Option[String]]
…Update
![Page 108: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/108.jpg)
How?
User String Option[String] …
Option[String]Option[
Option[String]]
…Update
Head
![Page 109: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/109.jpg)
How?
User String Option[String] …
Option[String]Option[
Option[String]]
…Update
Head The Rest…
![Page 110: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/110.jpg)
How?
Type constraints
Implicit methods
HLists
Labelled generic
Macros
…
![Page 111: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/111.jpg)
val user = User( 123L, "Bruce Wayne”, Some(“[email protected]”))
val update = Update( Some(“Batman”), None)
import bulletin._
val updated = user.merge(update)
// User(// 123L, // “Batman”, // Some(“[email protected]”))
![Page 112: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/112.jpg)
val user = User( 123L, "Bruce Wayne”, Some(“[email protected]”))
val update = Update( Some(“Batman”), None)
import bulletin._
val updated = user.merge(update)
// User(// 123L, // “Batman”, // Some(“[email protected]”))
![Page 113: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/113.jpg)
Summary
The compiler can help (maybe more than you thought).
Reduce boilerplate code.
![Page 114: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/114.jpg)
Using Power Tools
Can go one of two ways…
![Page 115: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/115.jpg)
Using Power Tools
Can go one of two ways…
What the hell is that?
It’s a monoid!I know this
![Page 116: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/116.jpg)
Simple
Types
Power
Share
![Page 117: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/117.jpg)
2008
‘The name Scala stands for “scalable language.”
The language is so named because it was designed
to grow with the demands of its users.’
![Page 118: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/118.jpg)
What have we seen?
Some straightforward parts of Scala—Clear, maintainable, helpful
Encoding ideas in types —flexibility, leads us to solutions
Let the compiler do it
—when it make sense for your demands
![Page 119: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/119.jpg)
Summary
Scala scaling with your needs —be opinionated in what you use, more when needed
Types working for us, not stopping us —functional programming, share what you learn
![Page 120: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/120.jpg)
Thanks!Richard Dallaway, @d6y
underscore.io
![Page 121: Types Working For You - qconlondon.com€¦ · Part 1 Straightforward Scala Part 2 Functional Programming Part 3 Typelevel Programming. Straightforward Scala — Part 1 — The only](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4d3e649acd17da0360a25/html5/thumbnails/121.jpg)
Thanks!Richard Dallaway, @d6y
underscore.io
Amanda Laucher Wesley Reisz Noel Welsh
Dave Gurnell Miles Sabin
Jono Ferguson Julio Capote
Alessandro Zoffoli