(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
Centralize the support libraries dependencies in gradle
Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.
A very good way is to separate gradle build files, defining something like:
root
--gradleScript
----dependencies.gradle
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> { | |
var shouldContinue = true | |
return takeWhile { | |
val result = shouldContinue | |
shouldContinue = pred(it) | |
result | |
} | |
} |
These are things that I found annoying writing a complex library in Kotlin. While I am also a Scala developer, these should not necessarily be juxtaposed w/ Scala (even if I reference Scala) as some of my annoyances are with features that Scala doesn't even have. This is also not trying to be opinionated on whether Kotlin is good/bad (for the record, I think it's good). I have numbered them for easy reference. I can give examples for anything I am talking about below upon request. I'm sure there are good reasons for all of them.
import kotlin.reflect.full.declaredMemberProperties | |
import kotlin.reflect.full.primaryConstructor | |
/** | |
* Merge two data classes | |
* | |
* The resulting data class will contain: | |
* - all fields of `other` which are non null | |
* - the fields of `this` for the fields which are null in `other` | |
* |
sealed class Result<A, E> { | |
fun <B> map(mapping: (A) -> B): Result<B, E> = | |
when (this) { | |
is Success -> Success(mapping(value)) | |
is Failure -> Failure(reason) | |
} | |
fun <B> bind(mapping: (A) -> Result<B, E>): Result<B, E> = | |
when (this) { | |
is Success -> mapping(value) |