jw
10/09/2017, 5:00 PMkarelpeeters
10/09/2017, 5:05 PMlistA.zip(listB) { (a, b) -> a.compareTo(b) }.find { it != 0 }
is the best I can come up with.jw
10/09/2017, 5:05 PMkarelpeeters
10/09/2017, 5:05 PMkarelpeeters
10/09/2017, 5:07 PMorangy
orangy
karelpeeters
10/09/2017, 5:08 PMorangy
orangy
orangy
dmitry.petrov
10/09/2017, 5:12 PMkarelpeeters
10/09/2017, 5:12 PMmap
, filter
, find
, ... operations on a locally created sequence that comes from a list. You'd need the sequence-lazyness for early return.orangy
listOf(1,2).filter { a(it) }.map { b(it) }
Here we call a(1), a(2) and then b(1), b(2)
If you fuse them, it would be a(1), b(1), a(2), b(2)karelpeeters
10/09/2017, 5:13 PMnatpryce
10/09/2017, 5:45 PMSortedSet<T>
and TreeSet<T>
defined as internal in kotlin.collections, but declared as the result type of public functions (such as toSortedSet()
)? This is in Kotlin 1.1.5-1jw
10/09/2017, 6:00 PMuli
10/12/2017, 6:43 AMCloseable.use(block)
being suboptimal regarding multiple closeables at a time.
Therfore I have implemented a `CloseableScope`which can add closeables to a List
like this:
try {
CloseableScope {
val noExceptionCloseable1 = NoExceptionCloseable1().autoClose()
val bodyExceptionCloseable = BodyExceptionCloseable().autoClose()
val closeExceptionCloseable1 = CloseExceptionCloseable1().autoClose()
val closeExceptionCloseable2 = CloseExceptionCloseable2().autoClose()
val noExceptionCloseable2 = NoExceptionCloseable2().autoClose()
noExceptionCloseable1.doSomething()
bodyExceptionCloseable.doSomething()
closeExceptionCloseable1.doSomething()
closeExceptionCloseable2.doSomething()
noExceptionCloseable2.doSomething()
}
} catch (t: Throwable) {
println(t)
}
CloseableScope(block)
opens the scope, Closeable.autoClose()
adds a Closeable
to the cleanup list and at the end of the scope, all Closeables on the list are closed.
The multi-exception semantics are modelled after java's try-with-ressourceuli
10/12/2017, 6:44 AMCloseable
.use(block) does not follow java's try-with-ressource semantics to add on-close-exceptions to a former exception (addSuppressed
), but just ignores them. Has this been discussed already? Are there any documented reasons for this difference in behaviour?uli
10/12/2017, 6:48 AMCloseableScope
?karelpeeters
10/12/2017, 6:50 AMkarelpeeters
10/12/2017, 6:51 AMuli
10/12/2017, 6:54 AMuli
10/12/2017, 6:56 AMfinally
blockuli
10/12/2017, 6:56 AMautoClose
karelpeeters
10/12/2017, 7:00 AMfinally
might be the better option, it's more difficult to forget your actual try
.uli
10/12/2017, 9:14 AMuli
10/12/2017, 9:16 AMkarelpeeters
10/12/2017, 9:20 AMuli
10/12/2017, 10:21 AM