Scala: building bridges
between programming
domains
Germán Ferrari
Scala Meetup Montevideo
Scala: building bridges between programming domains
Expressions
val label = if (age >= 18) "grownup" else "minor"
val result = tag match {
case "email" =>
try getEmail()
catch handleIOException()
case "postal" =>
scanLetter()
}
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 21)
Scoping and nesting
def fib(n: Int): Int = {
def loop(n: Int, a: Int, b: Int): Int = {
if (n <= 0) a
else loop(n - 1, b, a + b)
}
loop(n, 0, 1)
}
Case classes and pattern matching
sealed abstract class Expr
case class Number(n: Int) extends Expr
case class Plus(lhe: Expr, rhe: Expr) extends Expr
def eval(e: Expr): Int = e match {
case Number(n) => n
case Plus(l, r) => eval(l) + eval(r)
}
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 22)
Function values / higher-order functions
case class Person(name: String, age: Int)
val people = List(Person("Pedro", 18), Person("María", 20),
Person("Juan", 2), Person("José", 17))
def isMinor(p: Person) = p.age < 18
val (minors, adults) = people.partition(isMinor)
// minors = List(Person(Juan,2), Person(José,17))
// adults = List(Person(Pedro,18), Person(María,20)
val infants = minors.filter(_.age <= 3) // List(Person(Juan,2))
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 28)
Immutable collections
people.map(_.name) // List(Pedro, María, Juan, José)
people.groupBy(_.age)
// Map(17 -> List(Person(José,17)), 2 -> List(Person(Juan,2)),
// 20 -> List(Person(Pedro,20), Person(María,20)))
val nums = Set(1, 4, 5, 7)
nums.map(_ / 2) // Set(0, 2, 3)
val roman = Map("I" -> 1, "V" -> 5, "X" -> 10)
roman.map { case (k, v) => (v, k) } // Map(1 -> I, 5 -> V, 10 -> X)
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 29)
Parameterized types
class List[+A]
class Set[A]
class Function1[-A, +B]
type T1 = List[Number]
type T2 = Set[String]
type T3 = Function1[String, Int]
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 47)
Implicit parameters
def min[A](x: A, y: A)(implicit ord: Order[A]): A =
if (ord.lteqv(x, y)) x else y
min(2, 3) // 2
min("abc", "xyz") // "abc"
min(List(3, 8, 5), List(2, 7, 9)) // List(2, 7, 9)
Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 49)
Higher-kinded types
trait Functor[F[_]]
trait Applicative[F[_]]
trait Monad[F[_]]
type T1 = Functor[Option]
type T2 = Applicative[ValidatedA]
type T3 = Monad[List]
Bridges
https://ambientesdigital.com/puente-laguna-garzon-rafael-vinoly/
Bridge to functional programming
https://twitter.com/impurepics/status/1098663070535221253
Bridge to functional programming
https://twitter.com/impurepics/status/1098663070535221253
cats
cats-effect
Scala
Check scodec
object StringSpecification extends Properties("String") {
property("startsWith") = forAll { (a: String, b: String) =>
(a + b).startsWith(a)
}
// fails when `a` or `b` are the empty `String`
property("concatenate") = forAll { (a: String, b: String) =>
(a + b).length > a.length && (a + b).length > b.length
}
property("substring") = forAll { (a: String, b: String, c: String) =>
(a + b + c).substring(a.length, a.length + b.length) == b
}}
Bridge to functional programming
https://www.scalacheck.org
Bridge to functional programming
https://web.archive.org/web/20130113210808if_/http://podcast.is.ed.ac.uk:8080/Podcasts/informatics/Milner2012/2012-04-1
6/Milner2012_Panel-FunctProgLang-video.mp4
The future of functional programming languages. David MacQueen,
Xavier Leroy, Simon Peyton-Jones, Martin Odersky, Don Syme and
Phil Wadler - Milner Symposium 2012
“Escaping the box”
Bridge to concurrent and distributed programming
Monix
FS2
Reactive
Streams
Stream.resource(blockingExecutionContext).flatMap { blockingEC =>
io.file
.readAll[IO](Paths.get("fahrenheit.txt"), blockingEC, 4096)
.through(text.utf8Decode).through(text.lines)
.filter(s => !s.trim.isEmpty && !s.startsWith("//"))
.map(line => fahrenheitToCelsius(line.toDouble).toString)
.intersperse("n")
.through(text.utf8Encode)
.through(io.file.writeAll(Paths.get("celsius.txt"), blockingEC))
}.compile.drain.unsafeRunSync()
Bridge to concurrent and distributed programming
https://github.com/functional-streams-for-scala/fs2/blob/series/1.0/docs/ReadmeExample.md
Bridge to web and front-end programming
scalajs-react
slinky
scalajs-angular
Bridge to web and front-end programming
scalajs-react
slinky
scalajs-angular
http://www.lihaoyi.com/post/FromfirstprinciplesWhyIbetonScalajs.html
Bridge to web and front-end programming
// file: conf/routes
GET /clients/:id controllers.Clients.show(id: Long)
// file: Clients.scala
package controllers
class Clients() {
def show(id: Long) = Action {
Client.findById(id)
.map { client => Ok(views.html.Clients.display(client)) }
.getOrElse(NotFound)
}
} https://www.playframework.com/documentation/2.7.x/ScalaActions
Bridge to big data and data science
almond
Breeze
Spire
Bridge to big data and data science
almond
Breeze
Spire
Bridge to big data and data science
https://twitter.com/mandubian/status/1100713055426699264
Bridge to big data and data science
https://github.com/tensorflow/mlir
Tensorflow MLIR
"Multi-Level Intermediate Representation" Compiler
Infrastructure
Bridge to systems programming
http://www.scala-native.org
https://twitter.com/RichardWhaling/status/1090681460955271168
Scala Native
Bridge to systems programming
type Vec = CStruct3[Double, Double, Double]
val vec = stackalloc[Vec] // allocate c struct on stack
!vec._1 = 10.0 // initialize fields
!vec._2 = 20.0
!vec._3 = 30.0
length(vec) // pass by reference
http://www.scala-native.org
https://www.slideshare.net/Odersky/scala-the-simple-parts
https://slideshare.net/Odersky/oscon-keynote-working-hard-to-keep-it-simple
“flexible syntax, flexible types, user
defined operators, higher order
functions, implicits”
FIN

More Related Content

PDF
First-Class Patterns
PPT
OOP Core Concept
PPT
String slide
PPT
Collection v3
PDF
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
PDF
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
PPTX
Lecture 2 coding_principles
PDF
Java and j2ee_lab-manual
First-Class Patterns
OOP Core Concept
String slide
Collection v3
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
Lecture 2 coding_principles
Java and j2ee_lab-manual

What's hot (18)

PPTX
Lecture 2 coding_principles
PDF
Learn Java Part 11
PDF
Swift rocks! #1
PDF
Pythonic Graphics
PPT
JAVA OOP
PPT
3433 Ch09 Ppt
PDF
Refactoring
PDF
1z0 851 exam-java standard edition 6 programmer certified professional
PPTX
STACKS AND QUEUES CONCEPTS
PPT
Csphtp1 09
PDF
A taste of Functional Programming
PDF
Java cheatsheet
PDF
The java language cheat sheet
PDF
PDF
Mini-curso JavaFX Aula2
PDF
Functor, Apply, Applicative And Monad
PPT
Csphtp1 08
Lecture 2 coding_principles
Learn Java Part 11
Swift rocks! #1
Pythonic Graphics
JAVA OOP
3433 Ch09 Ppt
Refactoring
1z0 851 exam-java standard edition 6 programmer certified professional
STACKS AND QUEUES CONCEPTS
Csphtp1 09
A taste of Functional Programming
Java cheatsheet
The java language cheat sheet
Mini-curso JavaFX Aula2
Functor, Apply, Applicative And Monad
Csphtp1 08
Ad

Similar to Scala: building bridges between programming domains (20)

PDF
The Scala Programming Language
PPTX
Qcon2011 functions rockpresentation_scala
PPTX
Oop2010 Scala Presentation Stal
PDF
Hidden Gems in Swift
PDF
Scala @ TechMeetup Edinburgh
PDF
Scala in Places API
PDF
T3chFest 2016 - The polyglot programmer
PDF
Introduction to Functional Programming with Scala
ODP
Introduction to Scala
PDF
Introduction to Scala
PPT
Scala introduction
ODP
Scala Reflection & Runtime MetaProgramming
PDF
Scala introduction
PDF
Stepping Up : A Brief Intro to Scala
PDF
Starting with Scala : Frontier Developer's Meetup December 2010
PDF
Functional Programming in Scala
PDF
A bit about Scala
PPT
Scala presentation by Aleksandar Prokopec
PDF
Introduction to Scala for JCConf Taiwan
PDF
Scaladroids: Developing Android Apps with Scala
The Scala Programming Language
Qcon2011 functions rockpresentation_scala
Oop2010 Scala Presentation Stal
Hidden Gems in Swift
Scala @ TechMeetup Edinburgh
Scala in Places API
T3chFest 2016 - The polyglot programmer
Introduction to Functional Programming with Scala
Introduction to Scala
Introduction to Scala
Scala introduction
Scala Reflection & Runtime MetaProgramming
Scala introduction
Stepping Up : A Brief Intro to Scala
Starting with Scala : Frontier Developer's Meetup December 2010
Functional Programming in Scala
A bit about Scala
Scala presentation by Aleksandar Prokopec
Introduction to Scala for JCConf Taiwan
Scaladroids: Developing Android Apps with Scala
Ad

Recently uploaded (20)

PDF
IT Consulting Services to Secure Future Growth
PDF
Module 1 - Introduction to Generative AI.pdf
PPTX
AI Tools Revolutionizing Software Development Workflows
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PDF
Engineering Document Management System (EDMS)
PDF
solman-7.0-ehp1-sp21-incident-management
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PDF
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
PPTX
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
PPTX
Chapter_05_System Modeling for software engineering
PPTX
UNIT II: Software design, software .pptx
PDF
infoteam HELLAS company profile 2025 presentation
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
PPTX
Foundations of Marketo Engage: Nurturing
IT Consulting Services to Secure Future Growth
Module 1 - Introduction to Generative AI.pdf
AI Tools Revolutionizing Software Development Workflows
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
Engineering Document Management System (EDMS)
solman-7.0-ehp1-sp21-incident-management
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
Comprehensive Guide to Digital Image Processing Concepts and Applications
Presentation - Summer Internship at Samatrix.io_template_2.pptx
Top 10 Project Management Software for Small Teams in 2025.pdf
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
Folder Lock 10.1.9 Crack With Serial Key
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
Chapter_05_System Modeling for software engineering
UNIT II: Software design, software .pptx
infoteam HELLAS company profile 2025 presentation
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
Foundations of Marketo Engage: Nurturing

Scala: building bridges between programming domains

  • 1. Scala: building bridges between programming domains Germán Ferrari Scala Meetup Montevideo
  • 3. Expressions val label = if (age >= 18) "grownup" else "minor" val result = tag match { case "email" => try getEmail() catch handleIOException() case "postal" => scanLetter() } Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 21)
  • 4. Scoping and nesting def fib(n: Int): Int = { def loop(n: Int, a: Int, b: Int): Int = { if (n <= 0) a else loop(n - 1, b, a + b) } loop(n, 0, 1) }
  • 5. Case classes and pattern matching sealed abstract class Expr case class Number(n: Int) extends Expr case class Plus(lhe: Expr, rhe: Expr) extends Expr def eval(e: Expr): Int = e match { case Number(n) => n case Plus(l, r) => eval(l) + eval(r) } Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 22)
  • 6. Function values / higher-order functions case class Person(name: String, age: Int) val people = List(Person("Pedro", 18), Person("María", 20), Person("Juan", 2), Person("José", 17)) def isMinor(p: Person) = p.age < 18 val (minors, adults) = people.partition(isMinor) // minors = List(Person(Juan,2), Person(José,17)) // adults = List(Person(Pedro,18), Person(María,20) val infants = minors.filter(_.age <= 3) // List(Person(Juan,2)) Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 28)
  • 7. Immutable collections people.map(_.name) // List(Pedro, María, Juan, José) people.groupBy(_.age) // Map(17 -> List(Person(José,17)), 2 -> List(Person(Juan,2)), // 20 -> List(Person(Pedro,20), Person(María,20))) val nums = Set(1, 4, 5, 7) nums.map(_ / 2) // Set(0, 2, 3) val roman = Map("I" -> 1, "V" -> 5, "X" -> 10) roman.map { case (k, v) => (v, k) } // Map(1 -> I, 5 -> V, 10 -> X) Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 29)
  • 8. Parameterized types class List[+A] class Set[A] class Function1[-A, +B] type T1 = List[Number] type T2 = Set[String] type T3 = Function1[String, Int] Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 47)
  • 9. Implicit parameters def min[A](x: A, y: A)(implicit ord: Order[A]): A = if (ord.lteqv(x, y)) x else y min(2, 3) // 2 min("abc", "xyz") // "abc" min(List(3, 8, 5), List(2, 7, 9)) // List(2, 7, 9) Based on https://www.slideshare.net/Odersky/scala-the-simple-parts (slide 49)
  • 10. Higher-kinded types trait Functor[F[_]] trait Applicative[F[_]] trait Monad[F[_]] type T1 = Functor[Option] type T2 = Applicative[ValidatedA] type T3 = Monad[List]
  • 12. Bridge to functional programming https://twitter.com/impurepics/status/1098663070535221253
  • 13. Bridge to functional programming https://twitter.com/impurepics/status/1098663070535221253 cats cats-effect Scala Check scodec
  • 14. object StringSpecification extends Properties("String") { property("startsWith") = forAll { (a: String, b: String) => (a + b).startsWith(a) } // fails when `a` or `b` are the empty `String` property("concatenate") = forAll { (a: String, b: String) => (a + b).length > a.length && (a + b).length > b.length } property("substring") = forAll { (a: String, b: String, c: String) => (a + b + c).substring(a.length, a.length + b.length) == b }} Bridge to functional programming https://www.scalacheck.org
  • 15. Bridge to functional programming https://web.archive.org/web/20130113210808if_/http://podcast.is.ed.ac.uk:8080/Podcasts/informatics/Milner2012/2012-04-1 6/Milner2012_Panel-FunctProgLang-video.mp4 The future of functional programming languages. David MacQueen, Xavier Leroy, Simon Peyton-Jones, Martin Odersky, Don Syme and Phil Wadler - Milner Symposium 2012 “Escaping the box”
  • 16. Bridge to concurrent and distributed programming Monix FS2 Reactive Streams
  • 17. Stream.resource(blockingExecutionContext).flatMap { blockingEC => io.file .readAll[IO](Paths.get("fahrenheit.txt"), blockingEC, 4096) .through(text.utf8Decode).through(text.lines) .filter(s => !s.trim.isEmpty && !s.startsWith("//")) .map(line => fahrenheitToCelsius(line.toDouble).toString) .intersperse("n") .through(text.utf8Encode) .through(io.file.writeAll(Paths.get("celsius.txt"), blockingEC)) }.compile.drain.unsafeRunSync() Bridge to concurrent and distributed programming https://github.com/functional-streams-for-scala/fs2/blob/series/1.0/docs/ReadmeExample.md
  • 18. Bridge to web and front-end programming scalajs-react slinky scalajs-angular
  • 19. Bridge to web and front-end programming scalajs-react slinky scalajs-angular http://www.lihaoyi.com/post/FromfirstprinciplesWhyIbetonScalajs.html
  • 20. Bridge to web and front-end programming // file: conf/routes GET /clients/:id controllers.Clients.show(id: Long) // file: Clients.scala package controllers class Clients() { def show(id: Long) = Action { Client.findById(id) .map { client => Ok(views.html.Clients.display(client)) } .getOrElse(NotFound) } } https://www.playframework.com/documentation/2.7.x/ScalaActions
  • 21. Bridge to big data and data science almond Breeze Spire
  • 22. Bridge to big data and data science almond Breeze Spire
  • 23. Bridge to big data and data science https://twitter.com/mandubian/status/1100713055426699264
  • 24. Bridge to big data and data science https://github.com/tensorflow/mlir Tensorflow MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure
  • 25. Bridge to systems programming http://www.scala-native.org https://twitter.com/RichardWhaling/status/1090681460955271168 Scala Native
  • 26. Bridge to systems programming type Vec = CStruct3[Double, Double, Double] val vec = stackalloc[Vec] // allocate c struct on stack !vec._1 = 10.0 // initialize fields !vec._2 = 20.0 !vec._3 = 30.0 length(vec) // pass by reference http://www.scala-native.org
  • 28. FIN