fancy error printing done
This commit is contained in:
17
src/main/kotlin/blitz/collections/Bounds.kt
Normal file
17
src/main/kotlin/blitz/collections/Bounds.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package blitz.collections
|
||||
|
||||
fun <T> List<T>.inBounds(index: Int): Boolean {
|
||||
if (index >= size)
|
||||
return false
|
||||
if (index < 0)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun <T> Vec<T>.inBounds(index: Int): Boolean {
|
||||
if (index >= size)
|
||||
return false
|
||||
if (index < 0)
|
||||
return false
|
||||
return true
|
||||
}
|
22
src/main/kotlin/blitz/collections/MergeNeighbors.kt
Normal file
22
src/main/kotlin/blitz/collections/MergeNeighbors.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package blitz.collections
|
||||
|
||||
fun <T, G> Iterable<T>.mergeNeighbors(
|
||||
to: MutableList<Pair<G, MutableList<T>>> = mutableListOf(),
|
||||
by: (T) -> G
|
||||
): MutableList<Pair<G, MutableList<T>>> {
|
||||
val out = mutableListOf<Pair<G, MutableList<T>>>()
|
||||
forEach {
|
||||
val b = by(it)
|
||||
if (b == out.lastOrNull()?.first)
|
||||
out.last().second.add(it)
|
||||
else
|
||||
out.add(b to mutableListOf(it))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
fun <T, G> Sequence<T>.mergeNeighbors(
|
||||
to: MutableList<Pair<G, MutableList<T>>> = mutableListOf(),
|
||||
by: (T) -> G
|
||||
): MutableList<Pair<G, MutableList<T>>> =
|
||||
asIterable().mergeNeighbors(to, by)
|
Reference in New Issue
Block a user