This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <I: Item> ItemContainer<I>.nbxShiftModified() { | |
var item: I | |
val slotsToShift = firstEmptySlot .. secondEmptySlot | |
for (slot in slotsToShift) { | |
item = items[slot] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <I: Item> ItemContainer<I>.codeusaShift(predicate: (I) -> Boolean = Item::isInvalidItem) { | |
val tempBank = items | |
var id = 0 | |
tempBank.forEachIndexed { index, item -> | |
if (!predicate(item)) { | |
items[id] = tempBank[id++] | |
} | |
} | |
for (index in id until items.size) { | |
items[index] = InvalidItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <I: Item> ItemContainer<I>.dementhiumShift(predicate: (I) -> Boolean = Item::isInvalidItem) { | |
val oldData: List<I> = items.toList() | |
items.clear() | |
var ptr = 0 | |
items.forEachIndexed { itemIndex, item -> | |
if (predicate(item)) { | |
set(ptr++, oldData[itemIndex]) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <I: Item> ItemContainer<I>.nbPartitionShift(predicate: (I) -> Boolean = Item::isInvalidItem) { | |
items | |
.partitionJoin(predicate) | |
.forEachIndexed { idx, item -> set(idx, item) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <I: Item> ItemContainer<I>.nbxShift(predicate: (I) -> Boolean = Item::isInvalidItem) { | |
var firstSlotToFill = -1 | |
var currentSlot = 0 | |
var item: Item | |
while (currentSlot < items.size) { | |
item = this[currentSlot] | |
if (predicate(item)) { | |
if (firstSlotToFill < 0) firstSlotToFill = currentSlot | |
currentSlot += 1 | |
continue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun interface ReturnString { | |
fun getString() | |
} | |
fun string(rs: ReturnString) = rs | |
fun main() { | |
val str = string { "A String" } | |
println(str.string) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun string(rs: ReturnString) = rs | |
fun main() { | |
val str = string { "A String" } | |
println(str.string) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val returnAString = ReturnString { "a string" } | |
fun main() { | |
println(returnAString.string) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ReturnString { | |
String getString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class AnimalImpl(override val name: String, override val noise: String): Animal | |
fun main() { | |
var roofus = AnimalImpl("Roofus", "woof") | |
roofus.also { it.makeNoise() } | |
} |
NewerOlder