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
Merge requests
!3
"git@ic-gitlab.epfl.ch:lara/inox.git" did not exist on "bd927ca6fe24581e1b045416637b819adb496c07"
Add alternative solution for orderDec
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Add alternative solution for orderDec
mb/alt-orderdec
into
main
Overview
0
Commits
1
Pipelines
1
Changes
1
Open
Matt Bovel
requested to merge
mb/alt-orderdec
into
main
2 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (HEAD)
and
latest version
latest version
951607c3
1 commit,
2 years ago
1 file
+
17
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/main/scala/concpar22final03/Problem3.scala
+
17
−
0
Options
@@ -30,6 +30,23 @@ trait Problem3:
soldCards
.
flatMap
{
_
=>
buyListOfCards
(
wantedDeck
)
}
}.
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
* money on your personal bank account. It returns a Future of Unit, which
* indicates when all sales are completed.
Loading