Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS-206 Demos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
CS-206 Demos
Commits
951607c3
Commit
951607c3
authored
2 years ago
by
Matt Bovel
Browse files
Options
Downloads
Patches
Plain Diff
Add alternative solution for orderDec
parent
0f473913
Branches
mb/alt-orderdec
No related tags found
1 merge request
!3
Add alternative solution for orderDec
Pipeline
#158104
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/concpar22final03/Problem3.scala
+17
-0
17 additions, 0 deletions
src/main/scala/concpar22final03/Problem3.scala
with
17 additions
and
0 deletions
src/main/scala/concpar22final03/Problem3.scala
+
17
−
0
View file @
951607c3
...
@@ -30,6 +30,23 @@ trait Problem3:
...
@@ -30,6 +30,23 @@ trait Problem3:
soldCards
.
flatMap
{
_
=>
buyListOfCards
(
wantedDeck
)
}
soldCards
.
flatMap
{
_
=>
buyListOfCards
(
wantedDeck
)
}
}.
flatten
}.
flatten
/** Alternative implementation of orderDeck.
*/
def
orderDecAlt
(
bag
:
MoneyBag
,
cardsToSell
:
List
[
Card
],
wantedDeck
:
List
[
String
]
)
:
Future
[
List
[
Card
]]
=
val
totalGivenMoney
=
cardsToSell
.
map
(
c
=>
valueOf
(
c
.
name
)).
sum
+
moneyIn
(
bag
)
val
totalNeededMoney
=
wantedDeck
.
map
(
valueOf
).
sum
if
totalGivenMoney
<
totalNeededMoney
then
return
Future
.
failed
(
new
NotEnoughMoneyException
())
val
soldCards
:
Future
[
Any
]
=
if
moneyIn
(
bag
)
!=
0
then
sellListOfCards
(
cardsToSell
).
zip
(
deposit
(
bag
))
else
sellListOfCards
(
cardsToSell
)
soldCards
.
flatMap
{
_
=>
buyListOfCards
(
wantedDeck
)
}
/** This helper function will sell the provided list of cards and put the
/** This helper function will sell the provided list of cards and put the
* money on your personal bank account. It returns a Future of Unit, which
* money on your personal bank account. It returns a Future of Unit, which
* indicates when all sales are completed.
* indicates when all sales are completed.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment