mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-10 12:10:10 +08:00
Improve ContactList
This commit is contained in:
parent
bf64571717
commit
a105a48350
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.contact
|
package net.mamoe.mirai.contact
|
||||||
|
|
||||||
import net.mamoe.mirai.utils.LockFreeLinkedList
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
|
||||||
import net.mamoe.mirai.utils.joinToString
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,3 +50,35 @@ inline fun <C : Contact> LockFreeLinkedList<C>.filteringGetOrNull(filter: (C) ->
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect all the elements into a [MutableList] then cast it as a [List]
|
||||||
|
*/
|
||||||
|
fun <E : Contact> ContactList<E>.toList(): List<E> = toMutableList()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect all the elements into a [MutableList].
|
||||||
|
*/
|
||||||
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
|
fun <E : Contact> ContactList<E>.toMutableList(): MutableList<E> = this.delegate.toMutableList()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect all the elements into a [MutableSet] then cast it as a [Set]
|
||||||
|
*/
|
||||||
|
fun <E : Contact> ContactList<E>.toSet(): Set<E> = toMutableSet()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect all the elements into a [MutableSet].
|
||||||
|
*/
|
||||||
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
|
fun <E : Contact> ContactList<E>.toMutableSet(): MutableSet<E> = this.delegate.toMutableSet()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a [Sequence] containing all the elements in [this] in the same order.
|
||||||
|
*
|
||||||
|
* Note that the sequence is dynamic, that is, elements are yielded atomically only when it is required
|
||||||
|
*/
|
||||||
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
|
fun <E : Contact> ContactList<E>.asSequence(): Sequence<E> {
|
||||||
|
return this.delegate.asSequence()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user