From 42ad5f8c5221724d5c0da8b12ee07f8c9816cd08 Mon Sep 17 00:00:00 2001 From: Simon Forsberg Date: Mon, 5 Apr 2021 00:54:14 +0200 Subject: [PATCH] Add List.shifted function --- .../src/main/kotlin/net/zomis/games/common/GameLists.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/games-core/src/main/kotlin/net/zomis/games/common/GameLists.kt b/games-core/src/main/kotlin/net/zomis/games/common/GameLists.kt index c23b38e6..addd7c9a 100644 --- a/games-core/src/main/kotlin/net/zomis/games/common/GameLists.kt +++ b/games-core/src/main/kotlin/net/zomis/games/common/GameLists.kt @@ -1,3 +1,8 @@ package net.zomis.games.common fun T.toSingleList(): List = listOf(this) +fun List.shifted(steps: Int): List { + require(steps >= 0) + require(steps < this.size) + return this.subList(steps, this.size) + this.subList(0, steps) +}