Skip to content

Instantly share code, notes, and snippets.

View nbness2's full-sized avatar

Curtis Woodard nbness2

View GitHub Profile
fun <I: Item> ItemContainer<I>.nbxShiftModified() {
var item: I
val slotsToShift = firstEmptySlot .. secondEmptySlot
for (slot in slotsToShift) {
item = items[slot]
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
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])
}
}
}
fun <I: Item> ItemContainer<I>.nbPartitionShift(predicate: (I) -> Boolean = Item::isInvalidItem) {
items
.partitionJoin(predicate)
.forEachIndexed { idx, item -> set(idx, item) }
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
fun interface ReturnString {
fun getString()
}
fun string(rs: ReturnString) = rs
fun main() {
val str = string { "A String" }
println(str.string)
}
@nbness2
nbness2 / Main.kt
Last active December 22, 2021 09:49
Last parameter SAM example
fun string(rs: ReturnString) = rs
fun main() {
val str = string { "A String" }
println(str.string)
}
@nbness2
nbness2 / Main.kt
Created December 22, 2021 09:43
Use ReturnString interface
val returnAString = ReturnString { "a string" }
fun main() {
println(returnAString.string)
}
@nbness2
nbness2 / ReturnString.java
Created December 22, 2021 09:40
Return String Interface
public interface ReturnString {
String getString();
}
@nbness2
nbness2 / AnimalImpl.kt
Last active December 22, 2021 09:17
Kotlin lambda example
data class AnimalImpl(override val name: String, override val noise: String): Animal
fun main() {
var roofus = AnimalImpl("Roofus", "woof")
roofus.also { it.makeNoise() }
}