Skip to content

Instantly share code, notes, and snippets.

View Grohden's full-sized avatar
:shipit:
*tec tec tec noises*

Gabriel Rohden Grohden

:shipit:
*tec tec tec noises*
View GitHub Profile
@Grohden
Grohden / StdExtensions.kt
Last active February 21, 2025 15:37
My common extension functions for kotlin
/**
* Forks a nullable into a non nullable,
*
* This differs from the if else expression
* which is thread unsafe and doesn't guarantee
* the non nullability even if the value was validated as non null
* by the if expression (due to concurrency)
* NOTE: need to check this :D, probably i need to use contracts like the std to assure what
* i said above
*
@Grohden
Grohden / LateMapBox.kt
Last active December 7, 2018 14:58
A lazy way to execute a map on a collection
import java.lang.ref.WeakReference
// It doesn't matter for the receiver which one is the received argument
typealias LateBoxList<R> = List<LateMapBox<*, R>>
fun <T, R> Iterable<T>.mapAsLateBox(mapper: (T) -> R): List<LateMapBox<T, R>> {
return this.map { LateMapBox(it, mapper) }
}
/**
@Grohden
Grohden / BundleEnumExtension.kt
Created August 23, 2018 03:58
Android Bundle enum support using kotlin extension methods
import android.os.Bundle
// Dunno if there's a better way to extend both bundle and intents, but
// you probably can extend intents in the same way
fun Bundle.putEnum(key:String, enum: Enum<*>){
putString(key, enum.name)
}
inline fun <reified T: Enum<T>> Bundle.getEnum(key:String): T {
@Grohden
Grohden / AngularServices.js
Created February 7, 2018 11:38
Get rid of AngularJS dependency injection using webpack
//An memoize fn would be good to use here.
const getService = (serviceName) => angular.element(document.body).injector().get(serviceName);
export default new Proxy({}, {
get (target, prop) {
return getService(prop);
}
});