Skip to content

Instantly share code, notes, and snippets.

View Megamiun's full-sized avatar

Gabryel Monteiro Megamiun

View GitHub Profile
@Megamiun
Megamiun / background.kt
Last active September 6, 2023 19:11
reactor-basics
showThreads = true
val clientIO = Schedulers.newParallel("client-io", 2)
val serverIO = Schedulers.newParallel("server-io", 2)
val serverMain = Schedulers.newParallel("server-main", 2)
fun ioFetchUserById(id: Int) =
Mono.defer { fetchUserById(id) }
.delayElement(Duration.of(400, MILLIS))
.subscribeOn(serverIO)
package br.com.gabryel.playground.rx
import io.reactivex.Observable
import io.reactivex.rxkotlin.toObservable
import io.reactivex.rxkotlin.zipWith
import java.time.LocalTime
import java.util.concurrent.TimeUnit
import kotlin.math.pow
fun main() {
// Inferência de Tipo
val clearlyAString = ""
fun thisFunctionClearlyReturnsANumber(first: Int, second: Int) = first + second
fun thisReturnsNumberOfCharactersOnString(possibleString: Any)?: Int {
if (possibleString !is String) {
return IllegalStateException()
// Agora o código sabe que possibleString é sem sombra de dúvida uma String
@Megamiun
Megamiun / Personal.kt
Last active May 19, 2019 21:12
Gists showing the difference of using the nullability resources from Kotlin
class PersonalInfo(val phone: String?)
class Person(val personalInfo: PersonalInfo?)
// It seems that a Delegate Class always forwards to the same instance that it was created with.
// But it opens a possible misunderstanding: If I declare the delegated instance in the constructor
// as a var, shouldn't it change behaviour when the var changes? Or shouldn't a delegated instance
// always be a val, so it can't be changed? I think I prefer the first, as it would give the user more choice.
// General Interface
interface Context {
fun print(printable: String)
}