This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DelegatedPreference<T>(val default: T, val preferencesManagerInstantiator:()->SharedPreferences) { | |
| val manager : SharedPreferences by Delegates.lazy(preferencesManagerInstantiator) | |
| [suppress("UNCHECKED_CAST")] | |
| fun get(thisRef: Any?, prop: PropertyMetadata): T { | |
| return when(default){ | |
| is Int -> manager.getInt(prop.name, this.default) as T | |
| else -> throw TypeNotImplementedException(prop.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %div | |
| %pre | |
| %code | |
| = preserve do | |
| :escaped | |
| <script> | |
| var a = 1; | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ¬[A] = A => Nothing | |
| type ∨[T, U] = ¬[¬[T] with ¬[U]] | |
| type ¬¬[A] = ¬[¬[A]] | |
| type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) } | |
| class FoldUnion[T](t: T) { | |
| def boxClass(x: java.lang.Class[_]): java.lang.Class[_] = x.toString match { | |
| case "byte" => manifest[java.lang.Byte].erasure | |
| case "char" => manifest[java.lang.Character].erasure | |
| case "short" => manifest[java.lang.Short].erasure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage: | |
| // p(instance)('privateMethod)(arg1, arg2, arg3) | |
| class PrivateMethodCaller(x: AnyRef, methodName: String) { | |
| def apply(_args: Any*): Any = { | |
| val args = _args.map(_.asInstanceOf[AnyRef]) | |
| def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass) | |
| val parents = _parents.takeWhile(_ != null).toList | |
| val methods = parents.flatMap(_.getDeclaredMethods) | |
| val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found")) |