Skip to content

Instantly share code, notes, and snippets.

View jivimberg's full-sized avatar

Juan Ignacio Vimberg jivimberg

View GitHub Profile
@staltz
staltz / introrx.md
Last active April 18, 2024 15:33
The introduction to Reactive Programming you've been missing
@gabrielemariotti
gabrielemariotti / README.md
Last active February 24, 2021 10:52
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)

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
@matklad
matklad / takeWhileInclusive.kt
Created December 24, 2016 21:03
An "inclusive" version of Kotlin's takeWhile
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = pred(it)
result
}
}
@cretz
cretz / kotlin-annoyances.md
Last active November 12, 2019 22:54
Kotlin Annoyances

Kotlin Annoyances

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.

  1. Arrays in data classes break equals/hashCode and ask you to overload it. If you are going to need to overload it and arrays have no overridability, why not make the least-often use case (the identity-comparison equals) the exception?
@josdejong
josdejong / merge.kt
Last active October 24, 2023 09:30
Merge two data classes in Kotlin
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`
*
@dam5s
dam5s / Result.kt
Last active June 22, 2022 21:28
Railway oriented programming in Kotlin - This is code accompanying my blog post https://medium.com/@its_damo/error-handling-in-kotlin-a07c2ee0e06f
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)