This file contains 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
/** | |
* Convert from units to another units e.g. from square feet to acres | |
* return original value if conversion units are not supported | |
* Usage: | |
* const convertedValue = convert(100).from('acres').to('square feet'); | |
* expected: | |
* 4356000 | |
*/ | |
class Converter { | |
private toUnits: string; |
This file contains 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 benchmark(block: () -> Unit): Unit { | |
val startTime = System.nanoTime() | |
block() | |
val endTime = System.nanoTime() | |
Log.i("Time take to execute in ${endTime - startTime)") | |
} | |
=== | |
fun onClickHandler() { | |
// onClickListener flows that handling Network Request, Database Persistence and UI Rendering |
This file contains 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
val startTime = System.nanoTime() | |
// onClickListener flows that handling Network Request, Database Persistence and UI Rendering | |
val endTime = System.nanoTime() | |
Log.i("Time take to execute in ${endTime - startTime)") |
This file contains 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
fun doAsyncOperation(val onCallback: (String) -> Unit?) { | |
// do lengthy computation operation | |
onCallback("result") | |
} | |
=== | |
doAsyncOperation { _ -> } | |
doAsyncOperation {result -> Log.v(result)} |
This file contains 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
fun doAsyncOperation(val onCallback: ((String) -> Unit)? = null) { | |
// do lengthy computation operation | |
onCallback?.invoke("result") | |
} | |
=== | |
doAsyncOperation() | |
doAsyncOperation {result -> Log.v(result)} |
This file contains 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
val dataTypeA = arrayListOf(1, 2, 3) | |
Observable.fromIterable(dataTypeA) | |
.map {element -> when (element) { | |
1 -> "one" | |
2 -> "two" | |
3 -> "three" | |
else -> "" | |
}} | |
.toList().toObservable() |