Hullaballoonatic
04/13/2019, 10:42 PMval a = 1, b = 2, c = 5
val d = "D", e = "e", f = "etc"
Right now it's kind of possible as:
val (a, b, c) = listOf(1, 2, 5)
val (d, e, f) = listOf("D", "e", "etc")
But I think the former is clearerRohan Maity
04/14/2019, 12:56 AMrobsonribeiro
04/14/2019, 2:55 PMSmallville7123
04/14/2019, 3:33 PMstreetsofboston
04/14/2019, 4:19 PMSmallville7123
04/14/2019, 4:31 PMjdiaz
04/14/2019, 5:07 PMSmallville7123
04/15/2019, 4:24 AM.forEach
inline fun forEach(action: (T?) -> Unit) {
val iter = iterator()
var it = iter.next()
while(it != null) {
action.invoke(p1 = it)
it = iter.next()
}
}
Smallville7123
04/15/2019, 4:24 AM.forEach
is part of java.Collections
right?Slackbot
04/15/2019, 4:32 AMSmallville7123
04/15/2019, 6:23 AMjava.util.ArrayDeque
in kotlin nativeSmallville7123
04/15/2019, 7:03 AMoverride fun iterator(): kotlin.collections.Iterator<T> {
return object : kotlin.collections.Iterator<T> {
var node = head
override fun hasNext(): Boolean {
if (node != null) {
if (node?.next != null) return true
}
return false
}
override fun next(): T {
if (node != null) {
val value = node?.value
node = node?.next
return value as T
}
throw Exception("No Such Element")
}
}
}
CLOVIS
04/15/2019, 10:00 AMAny?.filter
, Any?.map
etc extension functions, to help with null handling.
How would the compiler react if it is used in a file in which List.filter
(from the standard lib) is called? More precisely, if I write the following, which extension function would be called (assuming both are imported):
val l = listOf (...)
l.filter { it... }
In that case they are both valid choices by the compiler, since List
is also a Any?
. So, which one is called?nfrankel
04/15/2019, 10:11 AMthana
04/15/2019, 10:52 AMAyoub
04/15/2019, 12:55 PMSmallville7123
04/15/2019, 1:27 PMthana
04/15/2019, 1:37 PMAntanas A.
04/15/2019, 2:06 PM`
suspend fun <T, U> DataSource.mustHave(block: suspend T.() -> U): U =
((this as? T) ?: throw RuntimeException("Operation is not supported")).block()
`
and use it: dataSource.mustHave<DataSource.HasAddOperation> { add(command) }
Logically it should be able to infer U type automatically, but if I'm specifying first type T compiler requires me to specify also U type.
eg. dataSource.mustHave<DataSource.HasAddOperation, AddResult> { add(command) }
Is it possible to somehow declare that extension function in a way that U type be inferred automatically?LeoColman
04/15/2019, 2:22 PMSmallville7123
04/15/2019, 2:49 PMCloneable
as i cant find it in the docs nor in the search thing at kotlinlang.orgprojectmoon
04/15/2019, 3:01 PMprivate var job: Job
fun init() {
GlobalScope.launch { job = launch { task() } }
}
fun stop() {
GlobalScope.launch { job.cancelAndJoin() }
}
`
projectmoon
04/15/2019, 3:01 PMSmallville7123
04/15/2019, 5:23 PMif (returnDelimiters) false
else it.equals(str)
obobo
04/15/2019, 6:14 PMtekjar
04/15/2019, 6:15 PMsnowe
04/15/2019, 7:39 PMinternal
functions of open
classes in the same package in main correct?greg
04/16/2019, 3:29 AMSlackbot
04/16/2019, 6:42 AMSmallville7123
04/16/2019, 7:44 AMThrowable().printStackTrace()
as im trying to find what line in the function my function is throwing fromSmallville7123
04/16/2019, 7:44 AMThrowable().printStackTrace()
as im trying to find what line in the function my function is throwing fromtddmonkey
04/16/2019, 7:45 AMSmallville7123
04/16/2019, 7:45 AMtddmonkey
04/16/2019, 7:45 AMSmallville7123
04/16/2019, 7:52 AMfun abort(e: String = "Aborted"): Nothing {
println("Aborting with error: $e")
println("stack trace:")
Throwable().printStackTrace()
throw Exception(e)
}
fun main() {
a()
}
fun a() {
println("aborting from a:2 from SampleLinux.kt:20")
abort()
}
output:
aborting from a:2 from SampleLinux.kt:20
Aborting with error: Aborted
stack trace:
kotlin.Throwable
at kfun:sample.abort$default(kotlin.String;kotlin.Int)kotlin.Nothing (0x21a208)
at Konan_start (0x21a182)
at Konan_run_start (0x21a0f3)
at Konan_main (0x21a047)
at __libc_start_main (0x7f305064c223)
at (0x210029)
at ((nil))
Uncaught Kotlin exception: kotlin.Exception: Aborted
at kfun:sample.abort(kotlin.String)kotlin.Nothing (0x21a490)
at kfun:sample.abort$default(kotlin.String;kotlin.Int)kotlin.Nothing (0x21a208)
at Konan_start (0x21a182)
at Konan_run_start (0x21a0f3)
at Konan_main (0x21a047)
at __libc_start_main (0x7f305064c223)
at (0x210029)
at ((nil))
tddmonkey
04/16/2019, 7:54 AMSmallville7123
04/16/2019, 7:54 AMtddmonkey
04/16/2019, 7:54 AMSmallville7123
04/16/2019, 7:55 AMMike
04/16/2019, 12:22 PMval e = Exception(message)
e.printStackTrace()
throw e
or
throw Exception(message).also {
it.printStackTrace()
}
Smallville7123
04/16/2019, 1:52 PMMike
04/16/2019, 2:00 PMtddmonkey
04/16/2019, 2:11 PM`Thread.currentThread().stackTrace
Smallville7123
04/16/2019, 7:17 PM