Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scala code * 1 . Submissions MUST compile using SBT with UNCHANGED configuration and * tests with no compilation errors. Submissions with compilation errors *
Scala code
Submissions MUST compile using SBT with UNCHANGED configuration and
tests with no compilation errors. Submissions with compilation errors
will receive points. Note that refactoring the code will cause the
tests to fail.
You MUST NOT edit the SBT configuration and tests. Altering it in your
submission will result in points for this assignment.
You MAY use reassignment to variables and "val" and "var"
declarations you will have to
In all of the exercises in this file, you can only add code between the
existing for the valdef That is you cannot add a new
valdef directly inside the "storage" object.
object storage:
EXERCISE : Complete the following definition, so that "getAndSetSpy" is
a stateful function that when invoked it returns a pair.
The second component of the pair should behave like "getAndSet" above
with the exception noted next
The first component of the pair is a function that, when invoked,
returns the total number of times that a "set" call has been made.
That number should cover all calls to "set" made in all pairs created
via "getAndSetSpy". That is the total number is a piece of state
shared all "set" functions created via "getAndSetSpy".
For example:
val spy getAndSet getAndSetSpy
val spy getAndSet getAndSetSpy
val geta seta getAndSet
val geta seta getAndSet
seta
seta
spy
val res: Int
The result is not
val getAndSetSpy: Int, Int Int, Int Unit
TODO: Complete the definition.
throw UnsupportedOperationException
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started