Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implied import entry to sidebar
- Loading branch information
Showing
5 changed files
with
46 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
object PostConditions { | ||
opaque type WrappedResult[T] = T | ||
|
||
private object WrappedResult { | ||
def wrap[T](x: T): WrappedResult[T] = x | ||
def unwrap[T](x: WrappedResult[T]): T = x | ||
} | ||
|
||
def result[T] given (r: WrappedResult[T]): T = WrappedResult.unwrap(r) | ||
|
||
def (x: T) ensuring [T](condition: given WrappedResult[T] => Boolean): T = { | ||
implied for WrappedResult[T] = WrappedResult.wrap(x) | ||
assert(condition) | ||
x | ||
} | ||
} | ||
|
||
object Test { | ||
import PostConditions.{ensuring, result} | ||
val s = List(1, 2, 3).sum.ensuring(result == 6) | ||
} |
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