Skip to content

Instantly share code, notes, and snippets.

View arkivanov's full-sized avatar

Arkadii Ivanov arkivanov

View GitHub Profile
internal class KittenDataSourceImpl : KittenDataSource {
override fun load(limit: Int, offset: Int): Maybe<String> =
maybeFromFunction {
val url = URL(makeKittenEndpointUrl(limit = limit, offset = offset))
val connection = url.openConnection() as HttpURLConnection
connection
.inputStream
.bufferedReader()
.use(BufferedReader::readText)
internal actual fun KittenDataSource(): KittenDataSource = KittenDataSourceImpl()
internal class KittenDataSourceImpl : KittenDataSource {
override fun load(limit: Int, offset: Int): Maybe<String> =
maybe<String> { emitter ->
val callback: (NSData?, NSURLResponse?, NSError?) -> Unit =
{ data: NSData?, _, error: NSError? ->
if (data != null) {
emitter.onSuccess(NSString.create(data, NSUTF8StringEncoding).toString())
} else {
emitter.onComplete()
}
@arkivanov
arkivanov / DetailsFragment.kt
Last active May 28, 2020 06:56
Android Fragments communication
class DetailsFragment(output: (Output) -> Unit): Fragment() {
sealed class Output {
object CloseClicked : Output()
}
}
package com
import kotlin.random.Random
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
private const val count = 10000000
var counter = 0
package com
import kotlin.random.Random
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
private const val count = 10000
@ExperimentalTime
fun main() {
@arkivanov
arkivanov / MviKmpReducer.kt
Created April 16, 2020 21:00
MviKmpReducer.kt
typealias Reducer<State, Effect> = (State, Effect) -> State
@arkivanov
arkivanov / MviKmpKittenComponent2.kt
Created April 16, 2020 20:43
MviKmpKittenComponent2.kt
class KittenComponent {
private val store =
KittenStoreImpl(
network = KittenStoreNetwork(dataSource = KittenDataSource()),
parser = KittenStoreParser
)
private var view: KittenView? = null
private var startStopScope: DisposableScope? = null
@arkivanov
arkivanov / MviKmpKittenComponent1.kt
Created April 16, 2020 20:40
MviKmpKittenComponent1.kt
class KittenComponent {
fun onViewCreated(view: KittenView) {
}
fun onStart() {
}
fun onStop() {
}
@arkivanov
arkivanov / MviKmpEventToIntent.kt
Created April 16, 2020 20:39
MviKmpEventToIntent.kt
internal fun Event.toIntent(): Intent =
when (this) {
is Event.RefreshTriggered -> Intent.Reload
}