File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/main/scala/ScalaPlayground/Lift/Immutable Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,15 @@ case class Lift(
41
41
42
42
inline def nearestPassengerTarget : Option [Floor ] =
43
43
people.filter(_.matchesDirection(this )).map(_.destination).minByOption(floor => Math .abs(floor - position))
44
+
45
+ inline def fixDirection (building : Building ): Lift =
46
+ position match
47
+ case 0 => copy(direction = Up )
48
+ case p if p == building.floors.length - 1 => copy(direction = Down )
49
+ case _ => this
50
+
51
+ inline def dropOff : Lift =
52
+ copy(people = people.filter(_.destination != position))
44
53
45
54
@ tailrec final def pickup (building : Building ): (Lift , Building ) =
46
55
val queue = building.floors(position)
@@ -52,13 +61,6 @@ case class Lift(
52
61
val emptierBuilding = building.copy(floors = building.floors.updated(position, emptierQueue))
53
62
fullerLift.pickup(emptierBuilding)
54
63
55
- inline def fixDirection (building : Building ): Lift = position match
56
- case 0 => copy(direction = Up )
57
- case p if p == building.floors.length - 1 => copy(direction = Down )
58
- case _ => this
59
-
60
- inline def dropOff : Lift = copy(people = people.filter(_.destination != position))
61
-
62
64
inline def align (building : Building ): Lift =
63
65
List (nearestPassengerTarget, building.nearestRequestInSameDirection(this )).flatten
64
66
.minByOption(floor => Math .abs(floor - position))
You can’t perform that action at this time.
0 commit comments