SlideShare une entreprise Scribd logo
1  sur  20
Scala collections
architecture:
DRY done well
Ofer Ron| October 2013
Huh?
Our goal is understanding:
def map[B, That](f: A => B)
(implicit bf: CanBuildFrom[Repr, B, That]): That
The collection traits
Traversable – the wanted behavior
trait Traversable[+A] {
def foreach[U](f:A=>U)
def filter(p:A=>Boolean):???
}
What’s the right return type?
The challenge
The reasonable behavior
List[A] List[A]
filter(f:A=>Boolean)
Bonus question:
Set[A] Set[A]
filter(f:A=>Boolean)
String String
filter(f:Char=>Boolean)
Building every type
class Builder[-Elem,+To] {
def +=(elem: Elem): this.type = . . .
def result(): To = . . .
def clear() = . . .
}
TraversableLike – abstractions
trait TraversableLike[+Elem,+Repr] {
def newBuilder:Builder[Elem,Repr]
def foreach[U](f:Elem=>U)
def filter(p:Elem=>Boolean):Repr = {
val b = newBuilder
foreach (e => if (p(e)) b+= e)
b.result
}
}
TraversableLike – abstractions
trait Traversable[+Elem] extends
TraversableLike[Elem,Traversable[Elem]] {…}
Abstract on implementation and type
We can filter, now what?
The reasonable behavior for map
List[A] List[B]
map(f:A=>B)
Set[A] Set[B]
map(f:A=>B)
Can the old solution work?
BitSet
BitSet
Set[String]
Can the old solution work? – another example
Map[A,B]
Map[C,D]
Iterable[C]
Aside - Functional dependencies
trait Matrix, trait Vector
Matrix * Vector => Vector
Matrix * Matrix => Matrix
Int * Matrix => Matrix
Vector * Vector => undefined
Aside - Functional dependencies – cnt’d
trait Mult [A,B,C] {
def apply(a:A,b:B):C
}
def multiply[A,B,C](a:A,b:B)(implicit mult:Mult[A,B,C]) =
mult(a,b)
implicit object MatrixVectorMult extends
Mult[Matrix,Vector,Vector]
CanBuildFrom - Using Functional dependencies
trait TraversableLike[+A,+Repr] {
def map[B, That](f: A => B)
(implicit bf: CanBuildFrom[Repr, B, That]): That = ???
}
trait CanBuildFrom[-Collection, -NewElem, +Result] {
def apply(from: Collection): Builder[NewElem, Result]
}
The BitSet hierarchy
TraversableLike[+A,+Repr]
SetLike[A,+Repr]
BitSetLike[+This <: BitSetLike[This]
with Set[Int]]
Traversable[+A]
Set[A]
BitSet
A=Int
A=Int
CanBuildFrom - Using Functional dependencies
object Set {
implicit def canBuildFromSet[B] = new
CanBuildFrom[Set[_], B, Set[B]] {…}
}
object BitSet {
implicit def canBuildFromBitSet[B] = new
CanBuildFrom[BitSet, Int, BitSet] {…}
}
Static vs dynamic type
val els:Iterable[Int] = List(1,2,3)
Static type Dynamic type
def map[A,B](els:Iterable[A])(f:A=>B):Iterable[B] = els map f
val newEls:Iterable[String] = map(List(1,2,3))(_.toString)
We want dynamic type list
Static vs dynamic type – cnt’d
Compiler will capture: CanBuildFrom[Iterable[_],B,Iterable[B]]
We can follow the call chain to understand how the
correct dynamic type can be created
Static vs dynamic type – cnt’d
New Coursera course:
Principles of Reactive Programming
Martin Odersky, Erik Meijer and Roland Kuhn
Nov. 4th, 2013
Thank You
We’re hiring!

Contenu connexe

En vedette

How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 
Agile testing for mere mortals
Agile testing for mere mortalsAgile testing for mere mortals
Agile testing for mere mortalsDave Haeffner
 
Full Stack Testing Done Well
Full Stack Testing Done WellFull Stack Testing Done Well
Full Stack Testing Done WellDave Haeffner
 
Web ui tests examples with selenide, nselene, selene & capybara
Web ui tests examples with  selenide, nselene, selene & capybaraWeb ui tests examples with  selenide, nselene, selene & capybara
Web ui tests examples with selenide, nselene, selene & capybaraIakiv Kramarenko
 
You do not need automation engineer - Sqa Days - 2015 - EN
You do not need automation engineer  - Sqa Days - 2015 - ENYou do not need automation engineer  - Sqa Days - 2015 - EN
You do not need automation engineer - Sqa Days - 2015 - ENIakiv Kramarenko
 
Cross Platform Appium Tests: How To
Cross Platform Appium Tests: How ToCross Platform Appium Tests: How To
Cross Platform Appium Tests: How ToGlobalLogic Ukraine
 
Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Iakiv Kramarenko
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Iakiv Kramarenko
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 minIakiv Kramarenko
 
Selenium Users Anonymous
Selenium Users AnonymousSelenium Users Anonymous
Selenium Users AnonymousDave Haeffner
 
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]Iakiv Kramarenko
 
Cucumber Crash Course
Cucumber Crash CourseCucumber Crash Course
Cucumber Crash CourseDave Haeffner
 
Easy tests with Selenide and Easyb
Easy tests with Selenide and EasybEasy tests with Selenide and Easyb
Easy tests with Selenide and EasybIakiv Kramarenko
 

En vedette (17)

How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Agile testing for mere mortals
Agile testing for mere mortalsAgile testing for mere mortals
Agile testing for mere mortals
 
Full Stack Testing Done Well
Full Stack Testing Done WellFull Stack Testing Done Well
Full Stack Testing Done Well
 
Web ui tests examples with selenide, nselene, selene & capybara
Web ui tests examples with  selenide, nselene, selene & capybaraWeb ui tests examples with  selenide, nselene, selene & capybara
Web ui tests examples with selenide, nselene, selene & capybara
 
Selenium Basics
Selenium BasicsSelenium Basics
Selenium Basics
 
You do not need automation engineer - Sqa Days - 2015 - EN
You do not need automation engineer  - Sqa Days - 2015 - ENYou do not need automation engineer  - Sqa Days - 2015 - EN
You do not need automation engineer - Sqa Days - 2015 - EN
 
Cross Platform Appium Tests: How To
Cross Platform Appium Tests: How ToCross Platform Appium Tests: How To
Cross Platform Appium Tests: How To
 
Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 min
 
Bdd lessons-learned
Bdd lessons-learnedBdd lessons-learned
Bdd lessons-learned
 
Easy automation.py
Easy automation.pyEasy automation.py
Easy automation.py
 
Selenium Users Anonymous
Selenium Users AnonymousSelenium Users Anonymous
Selenium Users Anonymous
 
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
 
Cucumber Crash Course
Cucumber Crash CourseCucumber Crash Course
Cucumber Crash Course
 
Easy tests with Selenide and Easyb
Easy tests with Selenide and EasybEasy tests with Selenide and Easyb
Easy tests with Selenide and Easyb
 

Plus de LivePerson

Microservices on top of kafka
Microservices on top of kafkaMicroservices on top of kafka
Microservices on top of kafkaLivePerson
 
Graph QL Introduction
Graph QL IntroductionGraph QL Introduction
Graph QL IntroductionLivePerson
 
Measure() or die()
Measure() or die() Measure() or die()
Measure() or die() LivePerson
 
Resilience from Theory to Practice
Resilience from Theory to PracticeResilience from Theory to Practice
Resilience from Theory to PracticeLivePerson
 
System Revolution- How We Did It
System Revolution- How We Did It System Revolution- How We Did It
System Revolution- How We Did It LivePerson
 
Liveperson DLD 2015
Liveperson DLD 2015 Liveperson DLD 2015
Liveperson DLD 2015 LivePerson
 
Http 2: Should I care?
Http 2: Should I care?Http 2: Should I care?
Http 2: Should I care?LivePerson
 
Mobile app real-time content modifications using websockets
Mobile app real-time content modifications using websocketsMobile app real-time content modifications using websockets
Mobile app real-time content modifications using websocketsLivePerson
 
Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices LivePerson
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]LivePerson
 
Apache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePersonApache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePersonLivePerson
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern ApplicationLivePerson
 
Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API LivePerson
 
SIP - Introduction to SIP Protocol
SIP - Introduction to SIP ProtocolSIP - Introduction to SIP Protocol
SIP - Introduction to SIP ProtocolLivePerson
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceLivePerson
 
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...LivePerson
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceLivePerson
 
From a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonFrom a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonLivePerson
 
How can A/B testing go wrong?
How can A/B testing go wrong?How can A/B testing go wrong?
How can A/B testing go wrong?LivePerson
 

Plus de LivePerson (20)

Microservices on top of kafka
Microservices on top of kafkaMicroservices on top of kafka
Microservices on top of kafka
 
Graph QL Introduction
Graph QL IntroductionGraph QL Introduction
Graph QL Introduction
 
Measure() or die()
Measure() or die() Measure() or die()
Measure() or die()
 
Resilience from Theory to Practice
Resilience from Theory to PracticeResilience from Theory to Practice
Resilience from Theory to Practice
 
System Revolution- How We Did It
System Revolution- How We Did It System Revolution- How We Did It
System Revolution- How We Did It
 
Liveperson DLD 2015
Liveperson DLD 2015 Liveperson DLD 2015
Liveperson DLD 2015
 
Http 2: Should I care?
Http 2: Should I care?Http 2: Should I care?
Http 2: Should I care?
 
Mobile app real-time content modifications using websockets
Mobile app real-time content modifications using websocketsMobile app real-time content modifications using websockets
Mobile app real-time content modifications using websockets
 
Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]
 
Apache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePersonApache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePerson
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
 
Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API
 
SIP - Introduction to SIP Protocol
SIP - Introduction to SIP ProtocolSIP - Introduction to SIP Protocol
SIP - Introduction to SIP Protocol
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
 
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
From a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonFrom a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePerson
 
How can A/B testing go wrong?
How can A/B testing go wrong?How can A/B testing go wrong?
How can A/B testing go wrong?
 

Dernier

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Dernier (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Scala Collections Architecture: DRY Done Well

  • 1. Scala collections architecture: DRY done well Ofer Ron| October 2013
  • 2. Huh? Our goal is understanding: def map[B, That](f: A => B) (implicit bf: CanBuildFrom[Repr, B, That]): That
  • 4. Traversable – the wanted behavior trait Traversable[+A] { def foreach[U](f:A=>U) def filter(p:A=>Boolean):??? } What’s the right return type?
  • 5. The challenge The reasonable behavior List[A] List[A] filter(f:A=>Boolean) Bonus question: Set[A] Set[A] filter(f:A=>Boolean) String String filter(f:Char=>Boolean)
  • 6. Building every type class Builder[-Elem,+To] { def +=(elem: Elem): this.type = . . . def result(): To = . . . def clear() = . . . }
  • 7. TraversableLike – abstractions trait TraversableLike[+Elem,+Repr] { def newBuilder:Builder[Elem,Repr] def foreach[U](f:Elem=>U) def filter(p:Elem=>Boolean):Repr = { val b = newBuilder foreach (e => if (p(e)) b+= e) b.result } }
  • 8. TraversableLike – abstractions trait Traversable[+Elem] extends TraversableLike[Elem,Traversable[Elem]] {…} Abstract on implementation and type
  • 9. We can filter, now what? The reasonable behavior for map List[A] List[B] map(f:A=>B) Set[A] Set[B] map(f:A=>B)
  • 10. Can the old solution work? BitSet BitSet Set[String]
  • 11. Can the old solution work? – another example Map[A,B] Map[C,D] Iterable[C]
  • 12. Aside - Functional dependencies trait Matrix, trait Vector Matrix * Vector => Vector Matrix * Matrix => Matrix Int * Matrix => Matrix Vector * Vector => undefined
  • 13. Aside - Functional dependencies – cnt’d trait Mult [A,B,C] { def apply(a:A,b:B):C } def multiply[A,B,C](a:A,b:B)(implicit mult:Mult[A,B,C]) = mult(a,b) implicit object MatrixVectorMult extends Mult[Matrix,Vector,Vector]
  • 14. CanBuildFrom - Using Functional dependencies trait TraversableLike[+A,+Repr] { def map[B, That](f: A => B) (implicit bf: CanBuildFrom[Repr, B, That]): That = ??? } trait CanBuildFrom[-Collection, -NewElem, +Result] { def apply(from: Collection): Builder[NewElem, Result] }
  • 15. The BitSet hierarchy TraversableLike[+A,+Repr] SetLike[A,+Repr] BitSetLike[+This <: BitSetLike[This] with Set[Int]] Traversable[+A] Set[A] BitSet A=Int A=Int
  • 16. CanBuildFrom - Using Functional dependencies object Set { implicit def canBuildFromSet[B] = new CanBuildFrom[Set[_], B, Set[B]] {…} } object BitSet { implicit def canBuildFromBitSet[B] = new CanBuildFrom[BitSet, Int, BitSet] {…} }
  • 17. Static vs dynamic type val els:Iterable[Int] = List(1,2,3) Static type Dynamic type def map[A,B](els:Iterable[A])(f:A=>B):Iterable[B] = els map f val newEls:Iterable[String] = map(List(1,2,3))(_.toString) We want dynamic type list
  • 18. Static vs dynamic type – cnt’d Compiler will capture: CanBuildFrom[Iterable[_],B,Iterable[B]] We can follow the call chain to understand how the correct dynamic type can be created
  • 19. Static vs dynamic type – cnt’d New Coursera course: Principles of Reactive Programming Martin Odersky, Erik Meijer and Roland Kuhn Nov. 4th, 2013

Notes de l'éditeur

  1. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  2. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  3. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  4. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  5. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  6. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  7. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  8. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  9. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  10. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  11. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  12. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  13. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  14. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  15. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  16. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  17. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether
  18. Global research of 600 consumers’ expectation of help – when purchasing online, 1/3 expect to be helped immediately, whilewhen purchasing online, ¾ expect to be able to access help within 5 minutesif a response is not delivered in the expected timeframe 50% will shop elsewhere online, or abandon altogether