Skip to content

Instantly share code, notes, and snippets.


Juan Ignacio Vimberg jivimberg

View GitHub Profile
dam5s / Result.kt
Last active Jun 4, 2020
Railway oriented programming in Kotlin - This is code accompanying my blog post
View Result.kt
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)
josdejong / merge.kt
Last active Aug 13, 2020
Merge two data classes in Kotlin
View merge.kt
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`
cretz /
Last active Nov 12, 2019
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?
matklad / takeWhileInclusive.kt
Created Dec 24, 2016
An "inclusive" version of Kotlin's takeWhile
View takeWhileInclusive.kt
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = pred(it)
gabrielemariotti /
Last active Sep 8, 2020
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (

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:

staltz /
Last active Sep 21, 2020
The introduction to Reactive Programming you've been missing
You can’t perform that action at this time.