Remove toPairs helper in favor of stdlib functionality
This commit is contained in:
parent
35bd570c93
commit
60797c21d0
|
@ -1,7 +1,6 @@
|
||||||
package moe.kageru.kagebot
|
package moe.kageru.kagebot
|
||||||
|
|
||||||
import moe.kageru.kagebot.config.Config
|
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.Message
|
||||||
import org.javacord.api.entity.message.MessageAuthor
|
import org.javacord.api.entity.message.MessageAuthor
|
||||||
import org.javacord.api.entity.message.Messageable
|
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)")
|
throw IllegalStateException("Embed must have even number of content strings (title/content pairs)")
|
||||||
}
|
}
|
||||||
return withEmbed {
|
return withEmbed {
|
||||||
contents.toPairs().forEach { (heading, content) ->
|
contents.zipWithNext().forEach { (heading, content) ->
|
||||||
addField(heading, content)
|
addField(heading, content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,15 +130,4 @@ object Util {
|
||||||
Config.server.getMemberById(id).orElse(null)
|
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