SlideShare una empresa de Scribd logo
1 de 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!

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Más 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
 

Más 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?
 

Último

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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

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

Notas del editor

  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