jw
08/08/2016, 2:14 PMhastebrot
08/08/2016, 3:05 PMprettyPrint()
function for collections in Kotlin?yole
08/08/2016, 3:05 PMhastebrot
08/08/2016, 3:11 PMlist.joinToString(",\n ", "[\n ", "\n]")
.hastebrot
08/08/2016, 3:13 PMfun <T> List<T>.toPrettyString() = joinToString(",\n ", "[\n ", "\n]")
sreich
08/08/2016, 5:58 PMyole
08/08/2016, 5:59 PMsreich
08/08/2016, 6:03 PMsreich
08/08/2016, 6:03 PMsreich
08/08/2016, 6:03 PMfellshard
08/08/2016, 6:04 PMsreich
08/08/2016, 6:04 PMsreich
08/08/2016, 6:04 PMsreich
08/08/2016, 6:04 PMsreich
08/08/2016, 6:04 PMsreich
08/08/2016, 6:04 PMsreich
08/08/2016, 6:05 PMvoddan
08/08/2016, 6:06 PMgroostav
08/08/2016, 6:06 PMNothing
and its helper method TODO()
allows you to create really terse failing implementations for methodsgroostav
08/08/2016, 6:07 PMsreich
08/08/2016, 6:07 PMsreich
08/08/2016, 6:08 PMgroostav
08/08/2016, 6:09 PMgroostav
08/08/2016, 6:13 PMopen class AbstractStupidClass : StupidInterface{
override fun annoyingMethodOne(p1: Type1, p2: Type2): Type3 = TODO(); //please note, this is not shorthand, this is compliable kotlin code
override fun annoyingMethodTwo(p1: Type1) : Type 4 = TODO();
//...
override fun usefulMethod(interesting: InterestingType1): SomeType = TODO();
}
and then create your relevant implementations:
class MyUsefulType : AbstractStupidClass {
overridefun usefulMethod(interesting: InterestingType1): SomeType{
val x = doThings()//...
}
}
groostav
08/08/2016, 6:13 PMStupidInterface
class defines something like hundreds of methods, then you might look into dynamic proxies and aspect-oriented-programming as a way to route calls to it.groostav
08/08/2016, 6:18 PMval aStupidInstance = NullInstance() as AStupidInterface;
val usefulInstance = object: AStupidInterface by aStupidInstance {
override fun usefulMethod(intersting: Interesting): AnotherInteresting {
//...
}
}
worth noting, assuming performance isn't an issue, this becomes fairly trivial to do given the right semantics of dynamic
, if that ever makes it into the JVM side kotlin compiler.jw
08/08/2016, 6:24 PMgroostav
08/08/2016, 9:48 PMval Any.log : Logger get() = Logger.getLogger(this.javaclass.canonicalName)
operator fun Logger.get(level: Level) = //... would have to return some intermediate type 'LeveledLogger'
operator fun LeveledLogger.plusAssign(entryContent: () -> Pair<String, Exception>) = //...
which gives me the syntax
fun someMethod(){
try {
somethingComplicated();
}
catch(ex: ItWentBadException){
log[WARNING] += { "Its gonna blow!" to ex }
}
}
groostav
08/08/2016, 9:49 PMgroostav
08/08/2016, 9:49 PM