-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b661194
commit b7ea3be
Showing
5 changed files
with
114 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
model/transform/src/main/scala/aqua/model/transform/topology/strategy/Fail.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package aqua.model.transform.topology.strategy | ||
|
||
import aqua.model.transform.topology.Topology | ||
import aqua.model.ValueModel | ||
|
||
import aqua.model.{OnModel, XorModel} | ||
|
||
import cats.data.Chain | ||
import cats.Eval | ||
import cats.syntax.apply.* | ||
import cats.syntax.functor.* | ||
import cats.syntax.traverse.* | ||
import cats.syntax.option.* | ||
import cats.syntax.applicative.* | ||
|
||
object Fail extends Before with Begins with After { | ||
|
||
override def forceExit(current: Topology): Eval[Boolean] = | ||
Eval.now(false) // override just to be explicit | ||
|
||
override def beforeOn(current: Topology): Eval[List[OnModel]] = | ||
current.parent | ||
.map(_.cursor.op) | ||
.collect { case XorModel => | ||
current.prevSibling.traverse(_.beginsOn) | ||
} | ||
.flatSequence | ||
.flatMap( | ||
_.fold(super.beforeOn(current))(_.pure) | ||
) | ||
|
||
override def pathBefore(current: Topology): Eval[Chain[ValueModel]] = | ||
for { | ||
path <- super.pathBefore(current) | ||
begins <- current.beginsOn | ||
hop = begins.headOption | ||
.map(_.peerId) | ||
.filterNot( | ||
path.lastOption.contains | ||
) | ||
} yield path ++ Chain.fromOption(hop) | ||
} |