David W
05/19/2017, 9:08 AMblablupp
05/19/2017, 9:38 AMtheopaintsil
05/19/2017, 10:13 AMmipster
05/21/2017, 4:44 PM{
for (t in channels!!)
if (t.item1 === message.channelReceiver)
return false
return true
}
mipster
05/21/2017, 4:53 PMalexreidy
05/21/2017, 5:52 PMharmony
05/21/2017, 7:24 PMval x = y
if (x != null) {}
apatrida
05/21/2017, 11:37 PM*
which means nothing useful. There is a big lack of information. At any point do you know what type T is? and if not, how does the parseProperty
expect to work on unknown types, does it check against a list of instance types then performs its action? If there is no way to know outside of this function what type type is, then you need to change parseProperty
to accept <*>
as the type as well because you cannot say "give me a type T" to someone who can never know what is the type of T
swapper
05/22/2017, 7:23 AMnawar
05/22/2017, 2:47 PMSender
class all the way to all the classes that implements Clickable
interface Clickable {
fun click(message: String)
}
class Sender {
init {
Clickable.click("sending from 'Sender'") // is this possible?
}
}
class Button : Clickable {
override fun click(message: String) = println("button $message") // receiving the message here
}
trevjones
05/22/2017, 3:22 PMas?
that will effectively wrap it in a try catch and return null if the cast failstrevjones
05/23/2017, 8:52 PMDaniel
05/24/2017, 8:16 AMDaniel
05/24/2017, 8:42 AMfun <T> ArrayList<T>.transformAll(transform: (T) -> T) {
for(i in firstIndex..lastIndex) {
this[i] = transform(this[i])
}
}
@Test
fun `Should apply the transformation to each element of the array list`() {
// GIVEN
val list = arrayListOf(2, 3, 4)
// WHEN
list.transformAll { it * 2 }
// THEN
assertThat(list, `is`(equalTo(arrayListOf(4, 6, 8))))
}
mrtreinis
05/24/2017, 1:20 PMelect
05/24/2017, 1:34 PM$
in triple quote?sandeep
05/25/2017, 6:18 PMDaniel
05/25/2017, 7:53 PMArrayList<>
to vararg
parameters than *arrayList.toTypedArray()
?voddan
05/26/2017, 6:28 AMprintln((1..5).map {"*".repeat(it)}.joinToString(separator = "\n"))
you don't get much more cryptic than thattipsy
05/26/2017, 6:02 PMdierre
05/27/2017, 1:55 PMdeinspanjer
05/27/2017, 1:58 PMjaspersmit
05/29/2017, 12:28 PMval childUnitsById = units
.map { if(it.parent != null) it else null }
.filterNotNull()
.groupBy {it.parent!!}
moehritz
05/30/2017, 7:21 AMSqlServer
object for basically everything needed to interact with our database.
In Java, we stored that reference in a static variable, as it was accessed and needed in a lot of different places. As there is no "static" in Kotlin, I'm unsure about how do do it properly.
class Database { val sqlServer = SqlServer(...) }
Does not work, as I can't access it from somewhere else
class Database { companion object { val sqlServer = SqlServer(...) } }
Does not work, as I can't pass any configuration
object Database { val sqlServer = SqlServer(...) }
Does not work, no support for constructors or similarIn Java, we do this:
public static void main(String[] args) {
DbConfig dbCfg = new DbConfig(args);
Database.init(dbCfg);
//Database ready to use
Database.select(...);
}
It would be nice to store the sqlServer object immutable and as a nonnull value.
Maybe i'm just dumb rn, it's sort of my first kotlin project. 🙂 Thanks!chi
05/30/2017, 11:00 AMDaniel
05/30/2017, 12:09 PMfun isNewTarget(touched: Draft) = touched !== sourceTouched && touched !== targetTouched
might it be possible to simplify this?pmckenzie
05/30/2017, 2:32 PMHoldge
05/30/2017, 4:31 PManstaendig
05/30/2017, 6:19 PMdekee
05/31/2017, 6:49 AMval hr = {
for (i in 1..2) {
for (k in 1..180)
print("—")
println()
}
}
println("Thing one")
hr.invoke()
println("Thing two")
hr.invoke()
dekee
05/31/2017, 6:49 AMval hr = {
for (i in 1..2) {
for (k in 1..180)
print("—")
println()
}
}
println("Thing one")
hr.invoke()
println("Thing two")
hr.invoke()
perryprog
05/31/2017, 10:28 AMhr
without parens. It’s not really a big deal, it would just look better. adding .invoke()
is just longer than a regular function with hr()
.