$ function

  1. @pub
void $(
  1. void compute()
)

Performs compute if and only if asserts are enabled. Useful for debug-time computes that are not necessary in production and would only introduce overhead e.g. invariant checking or debug logging.

It conveys that compute is intended for checking or information gathering, clearly separating it from code which is actually achieving functionality.

Implementation

@pub void $(final void Function() compute)
{	assert
	(	()
		{	compute();
			return true;
		}(),
		'Asserted expression: it must always be true but it is false.'
	);
}