Commit a105a483 authored by Him188's avatar Him188

Improve ContactList

parent bf645717
...@@ -2,9 +2,7 @@ ...@@ -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) -> ...@@ -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()
}
\ No newline at end of file
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