uli
03/01/2017, 5:42 PMdimsuz
03/01/2017, 5:43 PMnfrankel
03/01/2017, 8:37 PMnkiesel
03/01/2017, 10:57 PM_
for unused parameters of lambda expressions (and it seems also for unused values in a destructive assignments). Why does that not also work for unused parameters of methods? e.g. fun main(_: Array<String>) {
cypher121
03/02/2017, 7:30 AMmain
, since parameter names should match parent's when overriding so that named arguments work properly. idea even has a warning for thataaverin
03/02/2017, 7:43 AMyole
03/02/2017, 7:45 AMmain
or implemented interface methods, even if you don't rename them to _
permalmberg
03/02/2017, 7:15 PMokkero
03/02/2017, 9:52 PMgerson
03/03/2017, 3:12 PMvoddan
03/04/2017, 8:09 PMribesg
03/05/2017, 9:29 AMfun <T> List<T>.batched(batchSize: Int): List<List<T>> {
check(batchSize > 0) { "Invalid value for parameter 'batchSize': $batchSize (should be greater than 0)" }
val batchAmount = (size + batchSize - 1) / batchSize
val result = List<MutableList<T>>(batchAmount) { ArrayList(batchSize) }
var index = 0
forEach { result[index++ / batchSize].add(it) }
return result
}
You seem to care about optimization, so note than when called on a LinkedList
, your implementation does a O(N) get
call on line 13yole
03/05/2017, 5:15 PMjasoet
03/06/2017, 2:59 AMgroostav
03/06/2017, 6:28 AMfun ParseNode.accept(visitor: Visitor){
when(this){
is NodeTypeA -> this.internalAccept(visitor::visitEnter, visitor::visitLeave)
}
}
private fun <T> T.internalAccept(enter: (T) -> Unit, leave: (T) -> Unit): Unit = TODO()
will not compile without the this.
infront of internalAccept
?
It seems like theres a corner case I'm hitting between smart casting and type inference that isnt covered here.seanf
03/06/2017, 6:57 AMdimsuz
03/06/2017, 12:11 PMptashcka
03/06/2017, 1:09 PMdstarcev
03/06/2017, 4:00 PMmapOf(…).toSortedMap(CASE_INSENSITIVE_ORDER)
robin
03/06/2017, 8:03 PMval any = object {
override fun equals(other: Any?) = true
}
but only works when doing any == "Test"
, not the other way around: "Test" == any
. Is there any way to make the latter work?eygraber
03/06/2017, 9:49 PMString?
would print int?
inline val <reified T : Any?> T.TAG get() = ((this as? Any)?.javaClass?.simpleName ?: "${T::class.java.simpleName ?: "null"}?").replace("CompanionObject", "")
jlleitschuh
03/06/2017, 10:56 PMtoMutableList
on a mutable list copy that list?
Otherwise, how do you copy a list? I could use the ArrayList
constructor but if there is a kotlin way of copying a list I'd rather do that.andrewoma
03/07/2017, 3:59 AMfun <T> split(values: List<T>, vararg lengths: Int): Sequence<List<T>> {
val lengthsSeq = lengths.iterator()
val valuesSeq = values.iterator()
return generateSequence { if (lengthsSeq.hasNext()) List<T>(lengthsSeq.next()) { valuesSeq.next() } else null }
}
val result = split(listOf("one", "two", "three", "four", "five", "six", "seven", "eight"), 3, 2, 3).associateBy { it.first() }
assertEquals(result, mapOf(
"one" to listOf("one", "two", "three"), //row length == 3
"four" to listOf("four", "five"), //len == 2
"six" to listOf("six", "seven", "eight") //len == 3
))
mg6maciej
03/08/2017, 8:18 AMcmd+B
, cmd+click
) or see args of constructor (cmd+P
inside brackets; tooltip is micro and empty), e.g.
public typealias ArrayList<E> = java.util.ArrayList<E>
mikehearn
03/08/2017, 9:20 AMdoubleu
03/08/2017, 11:01 AMgrahamborland
03/08/2017, 11:17 AM@field:[Inject Named("ActiveBudgetId")] internal lateinit var activeBudgetId: String
Not quite as nice as the Java equivalent
@Inject @Named("ActiveBudgetId") String activeBudgetId;
sannysanoff
03/08/2017, 12:36 PMvoddan
03/08/2017, 12:39 PMdiv
method???
http://stackoverflow.com/q/42666760/3144601spand
03/08/2017, 3:33 PMString.{ trim() }
so it would have the type String.() -> String
spand
03/08/2017, 3:33 PMString.{ trim() }
so it would have the type String.() -> String
robin
03/08/2017, 3:35 PMval test: String.() -> Unit = { trim() }
spand
03/08/2017, 3:39 PMval foo : String.() -> Unit = when(false){
true -> {}
false -> {}
}
and it fails to inferlupajz
03/08/2017, 3:51 PMval foo : String.() -> Unit = when(false){
true -> { {} }
false -> { {} }
}
mfulton26
03/08/2017, 3:56 PMval foo = when (false) {
true -> fun String.() {}
false -> fun String.() {}
}
robin
03/08/2017, 4:11 PMlupajz
03/08/2017, 4:14 PMrobin
03/08/2017, 4:21 PMval foo : String.() -> Unit = when(false){
true -> { -> }
false -> { -> }
}
Same amount of characters to type, but at least it's a bit easier to read imo.lupajz
03/08/2017, 4:27 PMrobin
03/08/2017, 4:28 PMspand
03/09/2017, 7:27 AM