checkInvariant

inline fun <T : HasInvariant, R> T.checkInvariant(message: String, block: T.() -> R): R

Execute block and validate the invariant condition before and after execution.

If invariant checks are disabled, this function executes block without validation.

Return

The result of executing block.

Parameters

message

The detail message for the exception if an invariant check fails.

block

The operation to execute on this object.

Type Parameters

T

The type that implements HasInvariant.

R

The return type of block.

Throws

If the invariant is false before or after block runs.


inline fun <T : HasInvariant> T.checkInvariant(message: String): T

Validate the invariant condition immediately if invariant checks are enabled.

Return

This object instance.

Parameters

message

The detail message for the exception if the invariant check fails.

Type Parameters

T

The type that implements HasInvariant.

Throws

If invariant checks are enabled and HasInvariant.invariant returns false.


inline fun <T : HasInvariant> T.checkInvariant(messageExpr: () -> String): T

Validate the invariant condition immediately if invariant checks are enabled.

Return

This object instance.

Parameters

messageExpr

A function that returns the message for the exception if the invariant check fails.

Type Parameters

T

The type that implements HasInvariant.

Throws

If invariant checks are enabled and HasInvariant.invariant returns false.