Adds a flatten to set utility

This commit is contained in:
Vitor Pamplona
2025-10-31 18:36:05 -04:00
parent 95cc0783fd
commit 3eb662851b
7 changed files with 23 additions and 8 deletions
@@ -20,6 +20,8 @@
*/
package com.vitorpamplona.quartz.nip01Core.tags.hashtags
import com.vitorpamplona.quartz.utils.flattenToSet
fun hashtagAlts(tag: String): Set<String> =
setOf(
tag,
@@ -30,6 +32,6 @@ fun hashtagAlts(tag: String): Set<String> =
},
)
fun hashtagAlts(tags: List<String>): Set<String> = tags.map { hashtagAlts(it) }.flatten().toSet()
fun hashtagAlts(tags: List<String>): Set<String> = tags.map { hashtagAlts(it) }.flattenToSet()
fun hashtagAlts(tags: Set<String>): Set<String> = tags.map { hashtagAlts(it) }.flatten().toSet()
fun hashtagAlts(tags: Set<String>): Set<String> = tags.map { hashtagAlts(it) }.flattenToSet()
@@ -46,3 +46,11 @@ fun <T> Iterable<T>.joinToStringLimited(
buffer.append(postfix)
return buffer.toString()
}
public fun <T> Iterable<Iterable<T>>.flattenToSet(): Set<T> {
val result = mutableSetOf<T>()
for (element in this) {
result.addAll(element)
}
return result
}