Skip to content

Instantly share code, notes, and snippets.

View danielocampo2's full-sized avatar

Daniel Ocampo danielocampo2

  • Remote
View GitHub Profile
@danielocampo2
danielocampo2 / MultiDistinctBy.kt
Last active January 13, 2023 21:20
multiDistinctBy function for Kotlin: Like stdlib distinctBy but for multiple fields
fun <T, K> Iterable<T>.multiDistinctBy(vararg selectors: (T) -> K): List<T> {
require(selectors.isNotEmpty())
val set = HashSet<Int>()
val distinct = ArrayList<T>()
for (element in this) {
val key = selectors.fold(0) { sum, selector ->
sum.plus(selector(element)?.hashCode() ?: 0) }
if (set.add(key))
@danielocampo2
danielocampo2 / CommonExtensions.kt
Created June 6, 2017 23:14 — forked from adavis/CommonExtensions.kt
Common Android Extensions in Kotlin
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE