Ricky
09/22/2019, 12:16 PMmingwX86
but is created for mingwX64
Albert
09/22/2019, 1:57 PMAndreas Unterweger
09/22/2019, 8:07 PMclass Test {
@test
internal fun name() {
val mock = mockk<Logic>()
every { mock.doSth() } returns 2
mock.doSth() shouldBe 2
val obj = object : HasLogic {}
obj.doSth() shouldBe 2
}
}
interface HasLogic {
fun doSth() = Logic.doSth()
}
object Logic {
fun doSth() = 1
}
Rakesh Kumar
09/23/2019, 6:53 AMgildor
09/23/2019, 9:09 AMRoberto Messina
09/23/2019, 9:10 AMuser
09/23/2019, 11:30 AMAndrey Shcheglov
09/23/2019, 12:26 PMswagger.{yaml,json}
? I'm looking for smth similar to what wadl2java
and https://editor.swagger.io tools can offer.thana
09/23/2019, 1:52 PMRuckus
09/23/2019, 2:27 PMDouble.Companion
are not const
? I cannot do const val USE_DEFAULT = Double.NEGATIVE_INFINITY
.napperley
09/24/2019, 3:56 AM~
operator ( https://stackoverflow.com/questions/1483504/java-what-does-mean )?dG
09/24/2019, 11:32 AMDico
09/24/2019, 12:20 PMkotlin.code.style=official
line in gradle.properties
actually do? Does the IDE read it?Lou Morda
09/24/2019, 5:39 PMMarcin Wiśniewski
09/24/2019, 9:04 PMXavier Lian
09/25/2019, 12:15 AMLuke
09/25/2019, 1:11 PM(0 until width).forEach { x ->
(0 until height).forEach { y ->
println("($x, $y)")
}
}
I would like to write code similar to:
(width rangeBy height).forEach { (x, y) -> println("($x, $y)") }
Note that width
and height
don’t come from an iterable object in my case.xenoterracide
09/25/2019, 5:45 PMBen Madore
09/25/2019, 7:36 PMclass PhotoLibException : RuntimeException {
constructor(message: String, ex: Exception?): super(message, ex) {}
constructor(message: String): super(message) {}
constructor(ex: Exception): super(ex) {}
}
what is the appropriate way to add another property to PhotoLibException?napperley
09/25/2019, 8:42 PMBoolean.toInt
extension function? Some platform libraries use a Int
like a Boolean, which are often found when using Kotlin Native with C libraries for example.Travis Griggs
09/25/2019, 10:02 PM(some.code)?.let { thing ->
makeHayWith(thing)
} ?: run {
mournNoThing()
}
(it follows Swift’s if let … {} else {}
pattern nicely)
But I discovered there’s a hole in this that burned us. I should have seen this and feel kind of silly since I did Smalltalk with ubiqutuous block closures for all control flow for years. The let/run pattern breaks down when you do this:
(some.code)?.let { thing ->
makeHayWith(thing)?.let { hay ->
bragAboutMy(hay)
}
} ?: run {
mournNoThing()
}
If makeHayWith
returns a null
, then the return value of the original .let
block will return null
, which causes the run
block to run in addition to the outer let
block. So what you thought was a nice substitute for Swift’s if let ... else
pattern has just been turned into a bug waiting to happen.
I’m aware of the “smart pointers” described in https://kotlinlang.org/docs/reference/null-safety.html, but these don’t really appeal to me. I like something a little more intentional and universally applied.
I rarely use the kotlin let pattern as an expression, almost always as a statement, so I toyed with writing my own variant that returned a distinct type (rather than the closure return type) so that I could through sugary magic do something more akin to the Swift let thing. But I’m not sure I want to stray that far from “idiomatic Kotlin”
I guess my question is, is there another pattern that I’m not aware of that I should be considering using?Bernhard
09/26/2019, 7:54 AMuser
09/26/2019, 11:30 AMBruno_
09/26/2019, 12:12 PMPaul Woitaschek
09/26/2019, 12:59 PMuser
09/26/2019, 2:50 PMBernhard
09/26/2019, 3:38 PMKroppeb
09/26/2019, 3:53 PMfun foo(){
bar(+"test")
bar(getValue("test"))
}
fun bar(t:Int){
}
fun <T>getValue(p: String):T = TODO()
operator fun <T>String.unaryPlus(): T = getValue(this)
arekolek
09/26/2019, 4:38 PMtyler
09/26/2019, 5:05 PM