I hereby claim:
- I am benjaminearley on github.
- I am bin_earley (https://keybase.io/bin_earley) on keybase.
- I have a public key ASCvE5Eheyzi-cejt9fDSxyQfOL7CKSWt8w1HDveMW6J3Ao
To claim this, I am signing this object:
data class Operation(val disk: Int, val source: Char, val destination: Char, val auxiliary: Char) | |
val calculate = DeepRecursiveFunction<Operation, Unit> { (disk, source, destination, auxiliary) -> | |
if (disk <= 0) Unit | |
else { | |
callRecursive(Operation(disk - 1, source, auxiliary, destination)) | |
println("Move disk $disk from tower [$source] to [$destination]") | |
callRecursive(Operation(disk - 1, auxiliary, destination, source)) | |
} | |
} |
// Combines the source Observable with other Observables to create an Observable whose values are calculated | |
// from the latest values of each, only when the source emits. | |
// Interactive Diagram: https://rxmarbles.com/#withLatestFrom | |
// Discussion Thread: https://github.com/Kotlin/kotlinx.coroutines/issues/1498 | |
fun <A, B : Any, R> Flow<A>.withLatestFrom(other: Flow<B>, transform: suspend (A, B) -> R): Flow<R> = flow { | |
coroutineScope { | |
val latestB = AtomicReference<B?>() | |
val outerScope = this | |
launch { | |
try { |
fun mergeSort(list: List<Int>): List<Int> { | |
fun merge(left: ConsList<Int>, right: ConsList<Int>): ConsList<Int> = | |
when { | |
left is Nil -> right | |
right is Nil -> left | |
else -> { | |
val leftHead = (left as Cons).head | |
val rightHead = (right as Cons).head | |
if (leftHead < rightHead) Cons(leftHead, merge(left.tail, right)) |
let fib x = fibHelper (x-1);; | |
let rec fibHelper x = if x <= 1 then x else fibHelper (x - 1) + fibHelper (x - 2);; | |
(* 11th Value *) | |
fib 11 |
val fib:Stream[BigInt] = { | |
def next(fib: Stream[BigInt]): Stream[BigInt] = (fib.head + fib.tail.head) #:: next(fib.tail) | |
0 #:: 1 #:: next(fib) | |
} | |
// Print 11th Value 55 | |
fib.drop(10).head |
fun Context.getBitmapFromVectorDrawable(@DrawableRes drawableRes: Int, @ColorRes colorRes: Int? = null): Bitmap? { | |
var drawable = ContextCompat.getDrawable(this, drawableRes) ?: return null | |
drawable = DrawableCompat.wrap(drawable).mutate() | |
colorRes?.let { | |
DrawableCompat.setTint( | |
drawable, | |
ContextCompat.getColor( | |
this, |
fun Context.getTintedDrawable(@DrawableRes drawable: Int, @ColorRes color: Int) = | |
ContextCompat.getDrawable( | |
this, | |
drawable | |
) | |
?.let { d -> | |
DrawableCompat.wrap(d) | |
} | |
?.apply { | |
DrawableCompat.setTint( |
fun Float.dipsToPixels() = | |
TypedValue.applyDimension( | |
TypedValue.COMPLEX_UNIT_DIP, | |
this, | |
Resources.getSystem().displayMetrics | |
) | |
fun Int.dipsToPixels() = toFloat().dipsToPixels().toInt() |
@file:Suppress("UNCHECKED_CAST") | |
fun main(args: Array<String>) { | |
val pair = pair("HELLO", 1) | |
println(pair.first().toLowerCase()) | |
println(pair.second() * 5) | |
} | |
typealias Pair<A, B> = ((A, B) -> Any?) -> Any? |
I hereby claim:
To claim this, I am signing this object: