check

inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT>

Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should return false if the value is not valid. You can specify a message to include in the error output.

You can use validate for more complex checks.

Example:

val opt by option().int().check("value must be even") { it % 2 == 0 }
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT>

Check the final argument value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should return false if the value is not valid. You can specify a lazyMessage the returns a message to include in the error output.

You can use validate for more complex checks.

Example:

val opt by option().int().check(lazyMessage={"$it is not even"}) { it % 2 == 0 }
@JvmName(name = nullableCheck)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT?>

Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should return false if the value is not valid. You can specify a message to include in the error output. The validator is not called if the delegate value is null.

You can use validate for more complex checks.

Example:

val opt by option().int().check("value must be even") { it % 2 == 0 }
@JvmName(name = nullableLazyCheck)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT?>

Check the final argument value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should return false if the value is not valid. You can specify a lazyMessage the returns a message to include in the error output. The validator is not called if the delegate value is null.

You can use validate for more complex checks.

Example:

val opt by option().int().check(lazyMessage={"$it is not even"}) { it % 2 == 0 }