Revert "Remove toPairs helper in favor of stdlib functionality"
This reverts commit 60797c21d09ff70f465745b2a9764d78a8a14fe4.
This commit is contained in:
parent
0ae5e83641
commit
e3219c7800
@ -2,6 +2,7 @@ package moe.kageru.kagebot
|
||||
|
||||
import moe.kageru.kagebot.Util.failed
|
||||
import moe.kageru.kagebot.config.Config
|
||||
import moe.kageru.kagebot.Util.toPairs
|
||||
import org.javacord.api.entity.message.Message
|
||||
import org.javacord.api.entity.message.MessageAuthor
|
||||
import org.javacord.api.entity.message.Messageable
|
||||
@ -54,7 +55,7 @@ object MessageUtil {
|
||||
throw IllegalStateException("Embed must have even number of content strings (title/content pairs)")
|
||||
}
|
||||
return withEmbed {
|
||||
contents.zipWithNext().forEach { (heading, content) ->
|
||||
contents.toPairs().forEach { (heading, content) ->
|
||||
addField(heading, content)
|
||||
}
|
||||
}
|
||||
|
@ -135,4 +135,15 @@ object Util {
|
||||
Config.server.getMemberById(id).orElse(null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a list of elements to pairs, retaining order.
|
||||
* The last element is dropped if the input size is odd.
|
||||
* [1, 2, 3, 4, 5] -> [[1, 2], [3, 4]]
|
||||
*/
|
||||
fun <T> Collection<T>.toPairs(): List<Pair<T, T>> = this.iterator().run {
|
||||
(0 until size / 2).map {
|
||||
Pair(next(), next())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user