SlideShare a Scribd company logo
1 of 16
Download to read offline
ENUMERATOR &> PLAY 
|>>> 
ITERATEE 
PLAY MEETUP HAMBURG, 6.10.2014 
MARKUS.KLINK@INO.IO 
@JOHEINZ
GIT CLONE HTTPS:// 
GITHUB.COM/INOIO/ 
ITERATEE-TALK 
! 
! 
! 
SBT ~RUN
SOME LINKS: 
PLAY DOCUMENTATION 
(MORE OR LESS INCOMPREHENSIBLE) 
HTTP://MANDUBIAN.COM/2012/08/27/UNDERSTANDING-PLAY2-ITERATEES-FOR-NORMAL-HUMANS/ 
(ADDRESSES SOME OF THE SHORTCOMINGS) 
HTTPS://JAZZY.ID.AU/2012/11/06/ITERATEES_FOR_IMPERATIVE_PROGRAMMERS.HTML 
(YEAH, MORE INFO) 
ACTIVATOR TEMPLATE (SEARCH FOR ITERATEES) 
HTTPS://GITHUB.COM/JROPER/PLAY-ITERATEES-EXTRAS 
HTTPS://WWW.PLAYFRAMEWORK.COM/DOCUMENTATION/2.3.X/API/SCALA/INDEX.HTML#PLAY.API.LIBS.3
DATA PROCESSING 
PIPELINE 
HARPER & CHRISTY DOING IT PURELY FUNCTIONAL
„REACTIVE STREAMS ARE 
TWO WAY, IT'S NOT JUST 
YOU, THE STREAM 
CONSUMER THAT IS 
REACTING TO INPUT, THE 
STREAM PRODUCER MUST 
REACT TO YOU BEING READY 
FOR INPUT.“ James Roper
OTHER 
IMPLEMENTATIONS 
SCALAZ STREAM 
SCALAZ ITERATEES (OUTDATED)
THE IMPORTANT BITS 
ENUMERATOR[A] 
PRODUCES VALUES OF TYPE A 
MONAD (COMPOSABLE WITH A CONTEXT) 
MANY UTILITIES IN COMPANION OBJECT 
SMART 
!
ENUMERATOR API 
Enumerator.apply[A](a: A*) : Enumerator[A] 
Enumerator.enumerate[A](a: TraversableOnce[A]) : Enumerator[A] 
Enumerator.generateM[A](e : => Future[Option[A]]) : Enumerator[A] 
ALL THE FLATMAP GOODIES + GIVEN AN ENUMERATOR[E] 
|>>[A](i: Iteratee[E, A]): Future[Iteratee[E, A]] 
|>>>[A](i: Iteratee[E, A]): Future[A] 
&>[To](enumeratee: Enumeratee[E, To]): Enumerator[To]
THE IMPORTANT BITS 
ENUMERATEE[A,B] 
TRANSFORMS VALUES FROM A => B 
! 
MANY UTILITIES IN COMPANION OBJECT 
! 
NOT AS DUMP AS I THOUGHT
THE IMPORTANT BITS 
ITERATEE[A,B] 
CONSUMES INPUT ELEMENTS OF TYPE A AND OUTPUTS B 
MONAD (COMPOSABLE WITH A CONTEXT) 
SUPER SMART 
! 
! 
! 
INPUT IS EITHER: 
A.EMPTY: INPUT.EMPTY 
B.EOF: INPUT.EOF 
C.OR CONTAINS AN A: INPUT.EL(A) 
! 
ITERATEE STATE IS EITHER: 
A. DONE CONSUMING WITH A RESULT 
B. READY TO CONSUME MORE CONT 
C. OR IN ERROR STATE
ITERATEE API 
ALL THE FLATMAP GOODIES + GIVEN AN ITERATEE[E,A] 
run: Future[A] 
COMMON PATTERN TO BUILD AN ITERATEE: 
def myIteratee(x: AllTheStateINeed, 
oForNothing: O) : Iterator[I,O] = Cont { 
case Input.EOF => Done(oForNothing, Input.EOF) 
case Input.Empty => myIterator(x, oForNothing) 
case in@Input(i) => // be done with o || change state and recurse 
// create an Error with Error(„message“, in) 
!
HINT 
WHEN USING DONE, 
ALWAYS SPECIFY THE 
NEXT INPUT EXPLICITLY 
(DEFAULTS TO 
INPUT.EMPTY)
ENUMERATEE ><> 
ENUMERATOR ENUMERATEE ITERATEE 
&> &>> 
ENUMERATOR ITERATEE 
ENUMERATEE API
ENUMERATEE API 
THINK OF AN ENUMERATOR AS A KIND OF 
TRANSFORMER, ADAPTER AND COLLECTION: 
TAKE, TAKEWHILE, 
GROUPED, 
DROP, DROPWHILE, 
FILTER, FILTERNOT, MAP, …
val processElement: Iteratee[Byte, Element] = for { 
_ <- findLeftBrace 
string <- consumeUntilRightBrace 
element <- { 
safeParse(string) match { 
case Success(element) => Done[Byte, Element](element) 
case Failure(_) => Error[Byte](s"$string not a valid element", Input.EOF) 
} 
} 
} yield element 
COMPOSE 
ITERATEES & ENUMERATORS 
USING FOR 
COMPREHENSIONS
IN PRINCIPLE IT’S EASY, 
IT IS JUST POWERFUL 
CODE

More Related Content

Similar to Iteratees/Enumerators in Play

The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016Codemotion
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_featuresAnis Berejeb
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
Web api routing
Web api routingWeb api routing
Web api routingEyal Vardi
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play FrameworkTreasury user10
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/OSimone Bordet
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive? Tomasz Kowalczewski
 
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/OTech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/OCodemotion
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -LynellBull52
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessThomas Gregory
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 

Similar to Iteratees/Enumerators in Play (20)

The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_features
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
Web api routing
Web api routingWeb api routing
Web api routing
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play Framework
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/OTech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
 
Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
CompilersAndLibraries
CompilersAndLibrariesCompilersAndLibraries
CompilersAndLibraries
 
Introduction to python scrapping
Introduction to python scrappingIntroduction to python scrapping
Introduction to python scrapping
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
Php-mysql by Jogeswar Sir
Php-mysql by Jogeswar SirPhp-mysql by Jogeswar Sir
Php-mysql by Jogeswar Sir
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Geminate Airtable Connector
Geminate Airtable ConnectorGeminate Airtable Connector
Geminate Airtable Connector
 

Recently uploaded

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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Iteratees/Enumerators in Play

  • 1. ENUMERATOR &> PLAY |>>> ITERATEE PLAY MEETUP HAMBURG, 6.10.2014 MARKUS.KLINK@INO.IO @JOHEINZ
  • 2. GIT CLONE HTTPS:// GITHUB.COM/INOIO/ ITERATEE-TALK ! ! ! SBT ~RUN
  • 3. SOME LINKS: PLAY DOCUMENTATION (MORE OR LESS INCOMPREHENSIBLE) HTTP://MANDUBIAN.COM/2012/08/27/UNDERSTANDING-PLAY2-ITERATEES-FOR-NORMAL-HUMANS/ (ADDRESSES SOME OF THE SHORTCOMINGS) HTTPS://JAZZY.ID.AU/2012/11/06/ITERATEES_FOR_IMPERATIVE_PROGRAMMERS.HTML (YEAH, MORE INFO) ACTIVATOR TEMPLATE (SEARCH FOR ITERATEES) HTTPS://GITHUB.COM/JROPER/PLAY-ITERATEES-EXTRAS HTTPS://WWW.PLAYFRAMEWORK.COM/DOCUMENTATION/2.3.X/API/SCALA/INDEX.HTML#PLAY.API.LIBS.3
  • 4. DATA PROCESSING PIPELINE HARPER & CHRISTY DOING IT PURELY FUNCTIONAL
  • 5. „REACTIVE STREAMS ARE TWO WAY, IT'S NOT JUST YOU, THE STREAM CONSUMER THAT IS REACTING TO INPUT, THE STREAM PRODUCER MUST REACT TO YOU BEING READY FOR INPUT.“ James Roper
  • 6. OTHER IMPLEMENTATIONS SCALAZ STREAM SCALAZ ITERATEES (OUTDATED)
  • 7. THE IMPORTANT BITS ENUMERATOR[A] PRODUCES VALUES OF TYPE A MONAD (COMPOSABLE WITH A CONTEXT) MANY UTILITIES IN COMPANION OBJECT SMART !
  • 8. ENUMERATOR API Enumerator.apply[A](a: A*) : Enumerator[A] Enumerator.enumerate[A](a: TraversableOnce[A]) : Enumerator[A] Enumerator.generateM[A](e : => Future[Option[A]]) : Enumerator[A] ALL THE FLATMAP GOODIES + GIVEN AN ENUMERATOR[E] |>>[A](i: Iteratee[E, A]): Future[Iteratee[E, A]] |>>>[A](i: Iteratee[E, A]): Future[A] &>[To](enumeratee: Enumeratee[E, To]): Enumerator[To]
  • 9. THE IMPORTANT BITS ENUMERATEE[A,B] TRANSFORMS VALUES FROM A => B ! MANY UTILITIES IN COMPANION OBJECT ! NOT AS DUMP AS I THOUGHT
  • 10. THE IMPORTANT BITS ITERATEE[A,B] CONSUMES INPUT ELEMENTS OF TYPE A AND OUTPUTS B MONAD (COMPOSABLE WITH A CONTEXT) SUPER SMART ! ! ! INPUT IS EITHER: A.EMPTY: INPUT.EMPTY B.EOF: INPUT.EOF C.OR CONTAINS AN A: INPUT.EL(A) ! ITERATEE STATE IS EITHER: A. DONE CONSUMING WITH A RESULT B. READY TO CONSUME MORE CONT C. OR IN ERROR STATE
  • 11. ITERATEE API ALL THE FLATMAP GOODIES + GIVEN AN ITERATEE[E,A] run: Future[A] COMMON PATTERN TO BUILD AN ITERATEE: def myIteratee(x: AllTheStateINeed, oForNothing: O) : Iterator[I,O] = Cont { case Input.EOF => Done(oForNothing, Input.EOF) case Input.Empty => myIterator(x, oForNothing) case in@Input(i) => // be done with o || change state and recurse // create an Error with Error(„message“, in) !
  • 12. HINT WHEN USING DONE, ALWAYS SPECIFY THE NEXT INPUT EXPLICITLY (DEFAULTS TO INPUT.EMPTY)
  • 13. ENUMERATEE ><> ENUMERATOR ENUMERATEE ITERATEE &> &>> ENUMERATOR ITERATEE ENUMERATEE API
  • 14. ENUMERATEE API THINK OF AN ENUMERATOR AS A KIND OF TRANSFORMER, ADAPTER AND COLLECTION: TAKE, TAKEWHILE, GROUPED, DROP, DROPWHILE, FILTER, FILTERNOT, MAP, …
  • 15. val processElement: Iteratee[Byte, Element] = for { _ <- findLeftBrace string <- consumeUntilRightBrace element <- { safeParse(string) match { case Success(element) => Done[Byte, Element](element) case Failure(_) => Error[Byte](s"$string not a valid element", Input.EOF) } } } yield element COMPOSE ITERATEES & ENUMERATORS USING FOR COMPREHENSIONS
  • 16. IN PRINCIPLE IT’S EASY, IT IS JUST POWERFUL CODE