mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-23 10:20:14 +08:00
Add ContactList.first
and `ContactList.firstOrNull
This commit is contained in:
parent
354cc2172d
commit
2cd2591ff6
@ -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 = ")")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user