From a105a48350626867e188438b12dd4658250eeaae Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 4 Feb 2020 12:23:38 +0800 Subject: [PATCH] Improve ContactList --- .../net.mamoe.mirai/contact/ContactList.kt | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt index 8d19d8102..ae59a5f2c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt @@ -2,9 +2,7 @@ package net.mamoe.mirai.contact -import net.mamoe.mirai.utils.LockFreeLinkedList -import net.mamoe.mirai.utils.MiraiInternalAPI -import net.mamoe.mirai.utils.joinToString +import net.mamoe.mirai.utils.* /** @@ -52,3 +50,35 @@ inline fun LockFreeLinkedList.filteringGetOrNull(filter: (C) -> return null } + +/** + * Collect all the elements into a [MutableList] then cast it as a [List] + */ +fun ContactList.toList(): List = toMutableList() + +/** + * Collect all the elements into a [MutableList]. + */ +@UseExperimental(MiraiInternalAPI::class) +fun ContactList.toMutableList(): MutableList = this.delegate.toMutableList() + +/** + * Collect all the elements into a [MutableSet] then cast it as a [Set] + */ +fun ContactList.toSet(): Set = toMutableSet() + +/** + * Collect all the elements into a [MutableSet]. + */ +@UseExperimental(MiraiInternalAPI::class) +fun ContactList.toMutableSet(): MutableSet = 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 ContactList.asSequence(): Sequence { + return this.delegate.asSequence() +} \ No newline at end of file