lazy messages for check/require

This commit is contained in:
sergeych committed 2025-12-21 22:49:35 +01:00
1 parent 3dfe98a93d
commit 92cb088f36
4 files changed
+32 -5

No files matched your search

+15
View File
@@ -87,8 +87,23 @@ While not strictly for testing, these functions help in defensive programming:
Throws an `IllegalArgumentException` if the condition is false. Use this for validating function arguments.
If we want to evaluate the message lazily:
require(condition) { "requirement not met: %s"(someData) }
In this case, formatting will only occur if the condition is not met.
### `check`
check(condition, message="check failed")
Throws an `IllegalStateException` if the condition is false. Use this for validating internal state.
With lazy message evaluation:
check(condition) { "check failed: %s"(someData) }
In this case, formatting will only occur if the condition is not met.