SlideShare a Scribd company logo
Scala's 
For 
expressions
First, 
an 
example 
• Music 
label 
has 
ar7sts 
• Ar7sts 
have 
albums 
• Albums 
have 
volumes 
• Volumes 
have 
tracks 
• Tracks 
have 
a 
name 
and 
dura7on
case class Label(artists: Seq[Artist], name: String) 
case class Artist(albums: Seq[Album], name: String) 
case class Album(volumes: Seq[Volume], name: String) 
case class Volume(tracks: Seq[Track]) 
case class Track(name:String, duration: Int)
Get 
all 
track 
names 
from 
a 
volume 
val volume = Volume(...) 
val names: Seq[String] = 
volume.tracks.map( t => t.name )
Get 
all 
track 
names 
from 
an 
album 
val album = Album(...) 
val names: Seq[String] = 
album.volumes.flatMap( 
volume => volume.tracks.map( 
track => track.name 
) 
)
Get 
all 
track 
names 
from 
an 
ar7st 
val artist = Artist(...) 
val names: Seq[String] = 
artist.albums.flatMap( 
album => album.volumes.flatMap( 
volume => volume.tracks.map( 
track => track.name 
) 
) 
)
Get 
all 
track 
names 
from 
an 
ar7st 
val artist = Artist(...) 
val names: Seq[String] = 
for { 
album <- artist.albums 
volume <- album.volumes 
track <- volume.tracks 
} yield track.name
Get 
all 
track 
names 
from 
a 
label 
val label = Label(...) 
val names: Seq[String] = 
for { 
artist <- label.artists 
album <- artist.albums 
volume <- album.volumes 
track <- volume.tracks 
} yield track.name
Tracks 
from 
mul7-­‐volume 
albums 
val label = Label(...) 
val names: Seq[String] = 
for { 
artist <- label.artists 
album <- artist.albums if album.volumes.size > 1 
volume <- album.volumes 
track <- volume.tracks 
} yield track
Reminders 
• Any 
data 
structure 
with 
map, 
flatmap 
and 
filter 
• Seman7cs 
of 
these 
depend 
on 
the 
type 
• For 
expressions 
always 
return 
a 
value 
• Type 
of 
resul7ng 
data 
structure 
driven 
by 
the 
first 
generator 
• Type 
of 
the 
contained 
elements 
driven 
by 
the 
yield
Other 
examples 
• Op7on 
• Try 
• Either 
• Future
What Are For Expressions in Scala?

More Related Content

Viewers also liked

Paul Partlow Highlighted Portfolio
Paul Partlow Highlighted PortfolioPaul Partlow Highlighted Portfolio
Paul Partlow Highlighted Portfolio
Paul Partlow
 
Taste of korea
Taste of koreaTaste of korea
Taste of korea
Marta Garcia Trincado
 
Value Classes in Scala | BoldRadius
Value Classes in Scala | BoldRadiusValue Classes in Scala | BoldRadius
Value Classes in Scala | BoldRadius
BoldRadius Solutions
 
String Interpolation in Scala | BoldRadius
String Interpolation in Scala | BoldRadiusString Interpolation in Scala | BoldRadius
String Interpolation in Scala | BoldRadius
BoldRadius Solutions
 
Cold drawn guide rail, Elevator guide Rail India
Cold drawn guide rail, Elevator guide Rail IndiaCold drawn guide rail, Elevator guide Rail India
Cold drawn guide rail, Elevator guide Rail India
N Liftee
 
Pattern Matching in Scala
Pattern Matching in ScalaPattern Matching in Scala
Pattern Matching in Scala
BoldRadius Solutions
 
Partial Functions in Scala
Partial Functions in ScalaPartial Functions in Scala
Partial Functions in Scala
BoldRadius Solutions
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
BoldRadius Solutions
 
Punishment Driven Development #agileinthecity
Punishment Driven Development   #agileinthecityPunishment Driven Development   #agileinthecity
Punishment Driven Development #agileinthecity
Louise Elliott
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?
BoldRadius Solutions
 
Immutability in Scala
Immutability in ScalaImmutability in Scala
Immutability in Scala
BoldRadius Solutions
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
BoldRadius Solutions
 
scientific method and the research process
scientific method and the research processscientific method and the research process
scientific method and the research process
Adebanji Ayeni
 
GSLV MARK 3
GSLV MARK 3GSLV MARK 3
GSLV MARK 3
APOORVA
 
Domain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureDomain Driven Design Through Onion Architecture
Domain Driven Design Through Onion Architecture
BoldRadius Solutions
 
Haptens
HaptensHaptens

Viewers also liked (18)

Paul Partlow Highlighted Portfolio
Paul Partlow Highlighted PortfolioPaul Partlow Highlighted Portfolio
Paul Partlow Highlighted Portfolio
 
Taste of korea
Taste of koreaTaste of korea
Taste of korea
 
Value Classes in Scala | BoldRadius
Value Classes in Scala | BoldRadiusValue Classes in Scala | BoldRadius
Value Classes in Scala | BoldRadius
 
String Interpolation in Scala | BoldRadius
String Interpolation in Scala | BoldRadiusString Interpolation in Scala | BoldRadius
String Interpolation in Scala | BoldRadius
 
Cold drawn guide rail, Elevator guide Rail India
Cold drawn guide rail, Elevator guide Rail IndiaCold drawn guide rail, Elevator guide Rail India
Cold drawn guide rail, Elevator guide Rail India
 
Pattern Matching in Scala
Pattern Matching in ScalaPattern Matching in Scala
Pattern Matching in Scala
 
Partial Functions in Scala
Partial Functions in ScalaPartial Functions in Scala
Partial Functions in Scala
 
Test
TestTest
Test
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
 
Earth moon 1
Earth moon 1Earth moon 1
Earth moon 1
 
Punishment Driven Development #agileinthecity
Punishment Driven Development   #agileinthecityPunishment Driven Development   #agileinthecity
Punishment Driven Development #agileinthecity
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?
 
Immutability in Scala
Immutability in ScalaImmutability in Scala
Immutability in Scala
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
 
scientific method and the research process
scientific method and the research processscientific method and the research process
scientific method and the research process
 
GSLV MARK 3
GSLV MARK 3GSLV MARK 3
GSLV MARK 3
 
Domain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureDomain Driven Design Through Onion Architecture
Domain Driven Design Through Onion Architecture
 
Haptens
HaptensHaptens
Haptens
 

More from BoldRadius Solutions

Introduction to the Typesafe Reactive Platform
Introduction to the Typesafe Reactive PlatformIntroduction to the Typesafe Reactive Platform
Introduction to the Typesafe Reactive Platform
BoldRadius Solutions
 
Towards Reliable Lookups - Scala By The Bay
Towards Reliable Lookups - Scala By The BayTowards Reliable Lookups - Scala By The Bay
Towards Reliable Lookups - Scala By The Bay
BoldRadius Solutions
 
Introduction to the Actor Model
Introduction to the Actor ModelIntroduction to the Actor Model
Introduction to the Actor Model
BoldRadius Solutions
 
What are Sealed Classes in Scala?
What are Sealed Classes in Scala?What are Sealed Classes in Scala?
What are Sealed Classes in Scala?
BoldRadius Solutions
 
How To Use Higher Order Functions in Scala
How To Use Higher Order Functions in ScalaHow To Use Higher Order Functions in Scala
How To Use Higher Order Functions in Scala
BoldRadius Solutions
 
Scala Days 2014: Pitching Typesafe
Scala Days 2014: Pitching TypesafeScala Days 2014: Pitching Typesafe
Scala Days 2014: Pitching Typesafe
BoldRadius Solutions
 
Demonstrating Case Classes in Scala
Demonstrating Case Classes in ScalaDemonstrating Case Classes in Scala
Demonstrating Case Classes in Scala
BoldRadius Solutions
 

More from BoldRadius Solutions (7)

Introduction to the Typesafe Reactive Platform
Introduction to the Typesafe Reactive PlatformIntroduction to the Typesafe Reactive Platform
Introduction to the Typesafe Reactive Platform
 
Towards Reliable Lookups - Scala By The Bay
Towards Reliable Lookups - Scala By The BayTowards Reliable Lookups - Scala By The Bay
Towards Reliable Lookups - Scala By The Bay
 
Introduction to the Actor Model
Introduction to the Actor ModelIntroduction to the Actor Model
Introduction to the Actor Model
 
What are Sealed Classes in Scala?
What are Sealed Classes in Scala?What are Sealed Classes in Scala?
What are Sealed Classes in Scala?
 
How To Use Higher Order Functions in Scala
How To Use Higher Order Functions in ScalaHow To Use Higher Order Functions in Scala
How To Use Higher Order Functions in Scala
 
Scala Days 2014: Pitching Typesafe
Scala Days 2014: Pitching TypesafeScala Days 2014: Pitching Typesafe
Scala Days 2014: Pitching Typesafe
 
Demonstrating Case Classes in Scala
Demonstrating Case Classes in ScalaDemonstrating Case Classes in Scala
Demonstrating Case Classes in Scala
 

Recently uploaded

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 

Recently uploaded (20)

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 

What Are For Expressions in Scala?

  • 2. First, an example • Music label has ar7sts • Ar7sts have albums • Albums have volumes • Volumes have tracks • Tracks have a name and dura7on
  • 3. case class Label(artists: Seq[Artist], name: String) case class Artist(albums: Seq[Album], name: String) case class Album(volumes: Seq[Volume], name: String) case class Volume(tracks: Seq[Track]) case class Track(name:String, duration: Int)
  • 4. Get all track names from a volume val volume = Volume(...) val names: Seq[String] = volume.tracks.map( t => t.name )
  • 5. Get all track names from an album val album = Album(...) val names: Seq[String] = album.volumes.flatMap( volume => volume.tracks.map( track => track.name ) )
  • 6. Get all track names from an ar7st val artist = Artist(...) val names: Seq[String] = artist.albums.flatMap( album => album.volumes.flatMap( volume => volume.tracks.map( track => track.name ) ) )
  • 7. Get all track names from an ar7st val artist = Artist(...) val names: Seq[String] = for { album <- artist.albums volume <- album.volumes track <- volume.tracks } yield track.name
  • 8. Get all track names from a label val label = Label(...) val names: Seq[String] = for { artist <- label.artists album <- artist.albums volume <- album.volumes track <- volume.tracks } yield track.name
  • 9. Tracks from mul7-­‐volume albums val label = Label(...) val names: Seq[String] = for { artist <- label.artists album <- artist.albums if album.volumes.size > 1 volume <- album.volumes track <- volume.tracks } yield track
  • 10. Reminders • Any data structure with map, flatmap and filter • Seman7cs of these depend on the type • For expressions always return a value • Type of resul7ng data structure driven by the first generator • Type of the contained elements driven by the yield
  • 11. Other examples • Op7on • Try • Either • Future