SlideShare a Scribd company logo
1 of 1
Download to read offline
can someone create an instance of the Shuffler actor and send it like a main class to test these
functions in SCALA, please? I already tried ChatGPT Don't use it, please
FOR THIS CODE:
import akka.actor._ case class Shuffle[T](deck: List[T], n: Int, isOutShuffle: Boolean) case class
Split(deck: List[String], faroShuffler: ActorRef, isOutShuffle: Boolean) case class
ShuffleType(isOutShuffle: Boolean) case class CollectCards(name: String, numCards: Int) case
class Card(card: String) case class ShuffledDeck[T](deck: List[T]) class Shuffler extends Actor {
var shufflesLeft = 0 var senderRef: ActorRef = _ def receive = { case Shuffle(deck: List[String],
n, isOutShuffle) => shufflesLeft = n senderRef = sender() val splitter =
context.actorOf(Props[Splitter]) splitter ! Split(deck, context.actorOf(Props[FaroShuffler]),
isOutShuffle) case ShuffledDeck(deck: List[String]) => shufflesLeft -= 1 if (shufflesLeft == 0) {
senderRef ! ShuffledDeck(deck) } } } class Splitter extends Actor { def receive = { case
Split(deck, faroShuffler, isOutShuffle) => val (left, right) = deck.splitAt(deck.length / 2)
faroShuffler ! ShuffleType(isOutShuffle) faroShuffler ! left faroShuffler ! right } } class
FaroShuffler extends Actor { var cardCollector: Option[ActorRef] = None var deck1:
List[String] = Nil var deck2: List[String] = Nil var isOutShuffle: Boolean = false def receive = {
case ShuffleType(out) => isOutShuffle = out case deck: List[String] => if (deck1.isEmpty)
deck1 = deck else deck2 = deck if (deck1.nonEmpty && deck2.nonEmpty) { val numCards =
deck1.length + deck2.length cardCollector = Some(context.actorOf(Props[CardCollector]))
cardCollector.foreach(_ ! CollectCards(self.path.name, numCards)) val (firstDeck, secondDeck)
= if (isOutShuffle) (deck2, deck1) else (deck1, deck2) val shuffledDeck = (for { i <- 0 until
firstDeck.length j = if (i < secondDeck.length) i * 2 + 1 else (i - secondDeck.length) * 2 card <-
List(firstDeck(i), secondDeck(j)) } yield card).toList cardCollector.foreach(_ !
ShuffledDeck(shuffledDeck)) deck1 = Nil deck2 = Nil } } } class CardCollector extends Actor {
var collectedCards: List[String] = Nil var senderRef: ActorRef = _ def receive = { case
CollectCards(name, numCards) => senderRef = sender() collectedCards = Nil
context.become(collectingCards(name, numCards)) } def collectingCards(name: String,
numCards: Int): Receive = { case Card(card) => collectedCards = card :: collectedCards if
(collectedCards.length == numCards) { senderRef ! ShuffledDeck(collectedCards.reverse)
context.unbecome() } } }

More Related Content

Similar to can someone create an instance of the Shuffler actor and send it lik.pdf

Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systemsleague
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturialWayne Tsai
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳Yuri Inoue
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does notSergey Bandysik
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdffeelinggifts
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform ResearchVasil Remeniuk
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Sri Ambati
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#bleis tift
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...PROIDEA
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation streamRuslan Shevchenko
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using ScalaSiarhiej Siemianchuk
 

Similar to can someone create an instance of the Shuffler actor and send it lik.pdf (20)

Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Concurrent Application Development using Scala
Concurrent Application Development using ScalaConcurrent Application Development using Scala
Concurrent Application Development using Scala
 

More from info189835

Can someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdfCan someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdfinfo189835
 
can someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdfcan someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdfinfo189835
 
can someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdfcan someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdfinfo189835
 
Can someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdfCan someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdfinfo189835
 
can someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdfcan someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdfinfo189835
 
Can anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdfCan anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdfinfo189835
 
can anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdfcan anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdfinfo189835
 
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdfCambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdfinfo189835
 
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdfCalifornia condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdfinfo189835
 
California continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdfCalifornia continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdfinfo189835
 
Calculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdfCalculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdfinfo189835
 
calculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdfcalculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdfinfo189835
 
Calculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdfCalculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdfinfo189835
 
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdfCalculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdfinfo189835
 
Calculate the of total (portfolio weight) for eachStock A pr.pdf
Calculate the  of total (portfolio weight) for eachStock A pr.pdfCalculate the  of total (portfolio weight) for eachStock A pr.pdf
Calculate the of total (portfolio weight) for eachStock A pr.pdfinfo189835
 
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdfCalculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdfinfo189835
 
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdfCada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdfinfo189835
 
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdfCada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdfinfo189835
 
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdfC coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdfinfo189835
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfinfo189835
 

More from info189835 (20)

Can someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdfCan someone help with the implementation of these generic ArrayList .pdf
Can someone help with the implementation of these generic ArrayList .pdf
 
can someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdfcan someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic DoublyLink.pdf
 
can someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdfcan someone help with the implementation of these generic LinkedList.pdf
can someone help with the implementation of these generic LinkedList.pdf
 
Can someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdfCan someone explain me the steps pleaseTake the provided files.pdf
Can someone explain me the steps pleaseTake the provided files.pdf
 
can someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdfcan someone briefly answer these questions please1) how socia.pdf
can someone briefly answer these questions please1) how socia.pdf
 
Can anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdfCan anyone help me to understand why Consider a two way ANOVA model.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdf
 
can anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdfcan anyone help Prokaryotes are highly successful biological organi.pdf
can anyone help Prokaryotes are highly successful biological organi.pdf
 
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdfCambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
 
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdfCalifornia condors (Gymnogyps californianus) are listed on the IUCN .pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
 
California continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdfCalifornia continues to face a water shortage. The quantity of water.pdf
California continues to face a water shortage. The quantity of water.pdf
 
Calculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdfCalculate the various ratios based on the following informationCa.pdf
Calculate the various ratios based on the following informationCa.pdf
 
calculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdfcalculate the return on assets calculate the return on equity ca.pdf
calculate the return on assets calculate the return on equity ca.pdf
 
Calculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdfCalculate the frequency of alleles A and B for the two populations s.pdf
Calculate the frequency of alleles A and B for the two populations s.pdf
 
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdfCalculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
 
Calculate the of total (portfolio weight) for eachStock A pr.pdf
Calculate the  of total (portfolio weight) for eachStock A pr.pdfCalculate the  of total (portfolio weight) for eachStock A pr.pdf
Calculate the of total (portfolio weight) for eachStock A pr.pdf
 
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdfCalculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
 
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdfCada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
 
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdfCada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
 
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdfC coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 

can someone create an instance of the Shuffler actor and send it lik.pdf

  • 1. can someone create an instance of the Shuffler actor and send it like a main class to test these functions in SCALA, please? I already tried ChatGPT Don't use it, please FOR THIS CODE: import akka.actor._ case class Shuffle[T](deck: List[T], n: Int, isOutShuffle: Boolean) case class Split(deck: List[String], faroShuffler: ActorRef, isOutShuffle: Boolean) case class ShuffleType(isOutShuffle: Boolean) case class CollectCards(name: String, numCards: Int) case class Card(card: String) case class ShuffledDeck[T](deck: List[T]) class Shuffler extends Actor { var shufflesLeft = 0 var senderRef: ActorRef = _ def receive = { case Shuffle(deck: List[String], n, isOutShuffle) => shufflesLeft = n senderRef = sender() val splitter = context.actorOf(Props[Splitter]) splitter ! Split(deck, context.actorOf(Props[FaroShuffler]), isOutShuffle) case ShuffledDeck(deck: List[String]) => shufflesLeft -= 1 if (shufflesLeft == 0) { senderRef ! ShuffledDeck(deck) } } } class Splitter extends Actor { def receive = { case Split(deck, faroShuffler, isOutShuffle) => val (left, right) = deck.splitAt(deck.length / 2) faroShuffler ! ShuffleType(isOutShuffle) faroShuffler ! left faroShuffler ! right } } class FaroShuffler extends Actor { var cardCollector: Option[ActorRef] = None var deck1: List[String] = Nil var deck2: List[String] = Nil var isOutShuffle: Boolean = false def receive = { case ShuffleType(out) => isOutShuffle = out case deck: List[String] => if (deck1.isEmpty) deck1 = deck else deck2 = deck if (deck1.nonEmpty && deck2.nonEmpty) { val numCards = deck1.length + deck2.length cardCollector = Some(context.actorOf(Props[CardCollector])) cardCollector.foreach(_ ! CollectCards(self.path.name, numCards)) val (firstDeck, secondDeck) = if (isOutShuffle) (deck2, deck1) else (deck1, deck2) val shuffledDeck = (for { i <- 0 until firstDeck.length j = if (i < secondDeck.length) i * 2 + 1 else (i - secondDeck.length) * 2 card <- List(firstDeck(i), secondDeck(j)) } yield card).toList cardCollector.foreach(_ ! ShuffledDeck(shuffledDeck)) deck1 = Nil deck2 = Nil } } } class CardCollector extends Actor { var collectedCards: List[String] = Nil var senderRef: ActorRef = _ def receive = { case CollectCards(name, numCards) => senderRef = sender() collectedCards = Nil context.become(collectingCards(name, numCards)) } def collectingCards(name: String, numCards: Int): Receive = { case Card(card) => collectedCards = card :: collectedCards if (collectedCards.length == numCards) { senderRef ! ShuffledDeck(collectedCards.reverse) context.unbecome() } } }