This file contains hidden or 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
import kotlinx.serialization.* | |
import kotlinx.serialization.descriptors.SerialDescriptor | |
import kotlinx.serialization.encoding.CompositeDecoder | |
import kotlinx.serialization.encoding.Decoder | |
import kotlinx.serialization.encoding.Encoder | |
import kotlinx.serialization.json.* | |
import kotlin.reflect.KType | |
import kotlin.reflect.full.isSubtypeOf | |
import kotlin.reflect.full.starProjectedType |
This file contains hidden or 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 <reified T> isNullable(): Boolean = null is T |
This file contains hidden or 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
/** | |
* allow to define callback wrappers that are protected from accidental multiple calls to resume/resumeWithException | |
* Created by daely on 3/30/2017. | |
*/ | |
class WrappedContinuation<T>(val c: Continuation<T>) : Continuation<T> { | |
var isResolved = false | |
override val context: CoroutineContext | |
get() = c.context | |
override fun resume(value: T) { |
This file contains hidden or 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
package net.aquadc.common | |
// Gist: https://gist.github.com/Miha-x64/5f626228b34175f827734596d6701008 | |
import java.util.* | |
// maps | |
inline fun <reified K : Enum<K>, V> enumMapOf(): MutableMap<K, V> { | |
return EnumMap<K, V>(K::class.java) | |
} |
This file contains hidden or 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
// Version using experimental co-routines in 1.1 thanks to @voddan on Slack | |
import kotlin.coroutines.experimental.buildSequence | |
fun <T> Sequence<T>.repeat() : Sequence<T> = buildSequence { | |
while(true) yieldAll(this@repeat) | |
} | |
fun main(args: Array<String>) { | |
sequenceOf(1, 2, 3).repeat().take(6).forEach { i -> println(i) } | |
} |
This file contains hidden or 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
class MyFragment: Fragment(){ | |
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
return UI { | |
linearLayout{ | |
editText() | |
button("OK") | |
} | |
}.view | |
} | |
} |