Skip to content

Commit 9490eec

Browse files
authored
Improvement: Use a sequence in the build task for sim result handling (#232)
1 parent 9f617f5 commit 9490eec

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/main/kotlin/com/lambda/interaction/managers/breaking/BreakRequest.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ data class BreakRequest private constructor(
143143
nowOrNothing: Boolean = false,
144144
builder: (BreakRequestBuilder.() -> Unit)? = null
145145
) = asSequence()
146-
.map { if (it is Dependent) it.lastDependency else it }
146+
.breakRequest(pendingInteractions, nowOrNothing, builder)
147+
148+
@BreakRequestDsl
149+
@JvmName("breakRequest3")
150+
context(automated: Automated)
151+
fun Sequence<BuildResult>.breakRequest(
152+
pendingInteractions: MutableCollection<BuildContext>,
153+
nowOrNothing: Boolean = false,
154+
builder: (BreakRequestBuilder.() -> Unit)? = null
155+
) = map { if (it is Dependent) it.lastDependency else it }
147156
.filterIsInstance<BreakResult.Break>()
148157
.sorted()
149158
.map { it.context }
@@ -152,7 +161,7 @@ data class BreakRequest private constructor(
152161
?.let { automated.breakRequest(it, pendingInteractions, nowOrNothing, builder) }
153162

154163
@BreakRequestDsl
155-
@JvmName("breakRequest3")
164+
@JvmName("breakRequest4")
156165
fun Automated.breakRequest(
157166
contexts: Collection<BreakContext>,
158167
pendingInteractions: MutableCollection<BuildContext>,

src/main/kotlin/com/lambda/interaction/managers/interacting/InteractRequest.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ data class InteractRequest private constructor(
7979
nowOrNothing: Boolean = false,
8080
builder: (PlaceRequestBuilder.() -> Unit)? = null
8181
) = asSequence()
82-
.map { if (it is Dependent) it.lastDependency else it }
82+
.interactRequest(pendingInteractions, nowOrNothing, builder)
83+
84+
@PlaceRequestDsl
85+
@JvmName("interactRequest2")
86+
context(automated: Automated)
87+
fun Sequence<BuildResult>.interactRequest(
88+
pendingInteractions: MutableCollection<BuildContext>,
89+
nowOrNothing: Boolean = false,
90+
builder: (PlaceRequestBuilder.() -> Unit)? = null
91+
) = map { if (it is Dependent) it.lastDependency else it }
8392
.filterIsInstance<InteractResult.Interact>()
8493
.sorted()
8594
.map { it.context }
@@ -88,7 +97,7 @@ data class InteractRequest private constructor(
8897
?.let { automated.interactRequest(it, pendingInteractions, nowOrNothing, builder) }
8998

9099
@PlaceRequestDsl
91-
@JvmName("interactRequest2")
100+
@JvmName("interactRequest3")
92101
fun Automated.interactRequest(
93102
contexts: Collection<InteractContext>,
94103
pendingInteractions: MutableCollection<BuildContext>,

src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,15 @@ class BuildTask private constructor(
119119
}
120120

121121
private fun AutomatedSafeContext.simulateAndProcess() {
122-
val results = runSafeAutomated { blueprint.structure.simulate() }
122+
val results =
123+
blueprint.structure
124+
.simulate()
125+
.asSequence()
123126

124127
DEFAULT.drawables = results
125128
.filterIsInstance<Drawable>()
126129
.plus(pendingInteractions.toList())
130+
.toList()
127131

128132
val viableResults = results
129133
.filter { result ->
@@ -141,7 +145,7 @@ class BuildTask private constructor(
141145
handleResult(bestResult, viableResults)
142146
}
143147

144-
private fun AutomatedSafeContext.handleResult(result: BuildResult, allResults: List<BuildResult>) {
148+
private fun AutomatedSafeContext.handleResult(result: BuildResult, allResults: Sequence<BuildResult>) {
145149
if (result !is Dependent && result !is Contextual && pendingInteractions.isNotEmpty()) return
146150

147151
when (result) {

0 commit comments

Comments
 (0)