-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
63 additions
and
95 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
arch/src/main/scala/dev/tchiba/arch/ddd/AssertionConcerns.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,17 @@ | ||
package dev.tchiba.arch.ddd | ||
|
||
trait AssertionConcerns { | ||
|
||
protected def requires[T](fs: T => Either[String, Unit]*)(value: T): Unit = { | ||
invariant(fs.map(_(value)): _*) | ||
} | ||
|
||
protected def invariant(es: Either[String, Unit]*): Unit = { | ||
es.fold(Right()) { (e1, e2) => | ||
for { | ||
_ <- e1 | ||
_ <- e2 | ||
} yield () | ||
}.left.foreach(e => throw new IllegalArgumentException("requirement failed: " + e)) | ||
} | ||
} |
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