From 60797c21d09ff70f465745b2a9764d78a8a14fe4 Mon Sep 17 00:00:00 2001 From: kageru Date: Thu, 1 Aug 2019 13:15:05 +0200 Subject: [PATCH] Remove toPairs helper in favor of stdlib functionality --- src/main/kotlin/moe/kageru/kagebot/MessageUtil.kt | 3 +-- src/main/kotlin/moe/kageru/kagebot/Util.kt | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/kotlin/moe/kageru/kagebot/MessageUtil.kt b/src/main/kotlin/moe/kageru/kagebot/MessageUtil.kt index d22ad8f..50f2475 100644 --- a/src/main/kotlin/moe/kageru/kagebot/MessageUtil.kt +++ b/src/main/kotlin/moe/kageru/kagebot/MessageUtil.kt @@ -1,7 +1,6 @@ package moe.kageru.kagebot 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 @@ -51,7 +50,7 @@ object MessageUtil { throw IllegalStateException("Embed must have even number of content strings (title/content pairs)") } return withEmbed { - contents.toPairs().forEach { (heading, content) -> + contents.zipWithNext().forEach { (heading, content) -> addField(heading, content) } } diff --git a/src/main/kotlin/moe/kageru/kagebot/Util.kt b/src/main/kotlin/moe/kageru/kagebot/Util.kt index d70f21c..269a7be 100644 --- a/src/main/kotlin/moe/kageru/kagebot/Util.kt +++ b/src/main/kotlin/moe/kageru/kagebot/Util.kt @@ -130,15 +130,4 @@ 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 Collection.toPairs(): List> = this.iterator().run { - (0 until size / 2).map { - Pair(next(), next()) - } - } }