addOrThrow

fun <E : Any> MutableCollection<E>.addOrThrow(element: E, lazyMessage: () -> Any = { "Element has already been added" })

Adds element to MutableCollection if it does not contain it yet. Throws an IllegalArgumentException with the result of calling lazyMessage if the collections already contains the element.

Important: This is a Public Preview API. It may be changed or removed at any time.

Throws

if element has already been added to the list.