Skip to content

Commit

Permalink
Add List#eachRepeated
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Nov 6, 2024
1 parent f05ad62 commit e024e2c
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ fun <T> List<T>.after(element: T, step: Int = 1): T =
get((indexOf(element) + step).mod(size))

fun <T> List<T>.before(element: T, step: Int = 1): T =
get((indexOf(element) - step).mod(size))
get((indexOf(element) - step).mod(size))

fun <T> List<T>.eachRepeated(times: Int): List<T> {
val list = ArrayList<T>(size * times)
for (element in this) {
repeat(times) { list.add(element) }
}
return list
}

0 comments on commit e024e2c

Please sign in to comment.