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 minesweeper(matrix: MutableList<MutableList<Boolean>>): MutableList<MutableList<Int>> { | |
val board = Array(matrix.size) { Array(matrix[0].size) { 0 } } | |
for (row in matrix.indices) | |
for (colum in matrix[0].indices) { | |
val surroundingCells = getSurroundingCells(row, colum) | |
val mines = calculateNumberFor(surroundingCells, matrix) | |
board[row][colum] = mines | |
Log.d("minesweeper for $row,$colum", mines.toString()) | |
} | |
return board.map { it.toMutableList() }.toMutableList() |
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
package com.syphyr.rezoom.ui.theme.widgetStyles | |
import androidx.compose.material3.MaterialTheme | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.text.TextStyle | |
@Composable | |
fun AppText(fontSize: FontSize = FontSize.Medium, fontFamily: FontFamily = FontFamily.Body, text: String, color: Color = Color.Unspecified) { |
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
/** | |
* Most of the code in the RxJ example was to create an observable which emits items with a random delay. | |
* This is more concisely done using flows. | |
*/ | |
val flow1 = (1..10).asFlow().onEach { | |
Log.d(TAG,"$it - generated") | |
delay(randomDelay()) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
randomDelayedValues() | |
.debounce(3,TimeUnit.SECONDS) | |
.subscribe({ Log.d("DebounceTest", "$it emission") }, {}, { Log.d("DebounceTest", "Completed") }) | |
} | |
//This observable will emit values spaced by random delays | |
fun randomDelayedValues()= Observable.create<Int> { emitter -> | |
var number = 1 | |
timer(randomDelay()) { |
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 flow1 = (1..10).asFlow().onEach { delay((1..5).random() * 1000L) } | |
val flow2 = (1..10).asFlow().onEach { delay((1..5).random() * 1000L) 1 | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val combinedFlow = flow1.combine(flow2){ | |
one,two-> | |
"$one $two" | |
} | |
lifecycleScope.launchWhenCreated { |
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 stream1() = Observable.intervalRange( 1,10,0,(1..5).random().toLong(), TimeUnit.SECONDS) | |
fun stream2() = Observable.intervalRange( 1,10,0,(1..5).random().toLong(), TimeUnit.SECONDS) | |
fun main() | |
{ | |
Observable.combineLatest(stream1(), stream2()) { one, two-> | |
"$one and $two" | |
}.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe({ | |
Log.d(TAG, "$it - emitted") | |
}, { |
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 flow1=(1..10).asFlow().onEach { delay((1..5).random() * 1000L) } | |
val flow2=(1..10).asFlow().onEach { delay((1..5).random() * 1000L) } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val combinedFlow = flow1.zip(flow2) { one, two -> | |
"$one $two" | |
} | |
lifecycleScope.launchWhenCreated { |
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 stream1() = Observable.intervalRange( 1,10,0,(1..5).random().toLong(), TimeUnit.SECONDS) | |
fun stream2() = Observable.intervalRange( 1,10,0,(1..5).random().toLong(), TimeUnit.SECONDS) | |
fun main() | |
{ | |
Observable.zip(stream1(), stream2()) { one, two -> | |
"$one and $two" | |
}.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe({ | |
Log.d(TAG, "$it - emitted") |
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 scope = CoroutineScope(Dispatchers.IO) // losely akin to subscribeOn | |
fun onCreate() | |
{ | |
scope.launch { // launch is one of the coroutine builder | |
val students = getStudentsFromApi() // this is a suspend function | |
withContext(Dispatchers.Main) // losely akin to observeOn - But keep in mind there is no concept of "observation" in Coroutines | |
{ | |
//We are on the main thread here | |
showToast("Received ${students.size} students") | |
} |
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
(the scope).launch{ | |
delay(1000L) | |
print("Hey , I just ran off the main. Technically I ran where the scope asked me to run") | |
} |
NewerOlder