Commit 2cd2591f authored by Him188's avatar Him188

Add `ContactList.first` and ``ContactList.firstOrNull`

parent 354cc217
......@@ -40,6 +40,15 @@ class ContactList<C : Contact>(@MiraiInternalAPI val delegate: LockFreeLinkedLis
fun containsAll(elements: Collection<C>): Boolean = elements.all { contains(it) }
fun isEmpty(): Boolean = delegate.isEmpty()
inline fun forEach(block: (C) -> Unit) = delegate.forEach(block)
fun first(): C {
forEach { return it }
throw NoSuchElementException()
}
fun firstOrNull(): C? {
forEach { return it }
return null
}
override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment