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

Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
league
 
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
feelinggifts
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
Vasil Remeniuk
 
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
 
仕事で使う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
 

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 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
info189835
 
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
info189835
 
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
info189835
 

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

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

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() } } }