Skip to content

Instantly share code, notes, and snippets.

View mbiamont's full-sized avatar

Melvin Biamont mbiamont

View GitHub Profile
/**
* Call [block] lambda for each subset from the longest to the shortest.
*/
inline fun String.forEachSubset(block: (String) -> Unit) {
for (i in length downTo 1) {
for (j in 0 until length + 1 - i) {
block(substring(j, i + j))
}
}
}
@mbiamont
mbiamont / resynchronize.kt
Last active August 12, 2019 06:51
Function to use synchronously a function returning its value by a lambda
package com.github.gist.mbiamont
import kotlinx.coroutines.runBlocking
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
inline fun <T> resynchronize(crossinline block: (onSuccess: (result: T) -> Unit, onError: (e: Throwable) -> Unit) -> Unit): T {
return runBlocking {