sanity/pairAdjacentViolators 42
A JVM implementation of the Pair Adjacent Violators algorithm for isotonic regression
Simple server for proxy requests and host static files written in Kotlin and Undertow.
Полный перевод книги про построение сообществ: «Социальная архитектура»
Create pictures of yourself on every commit/push/whatever git hook. Linux, Git.
Вводный курс в Kotlin
BelarusKUG/Kotlin-Everywhere 3
Materials from Kotlin/Everywhere Minsk event
DI containers comparison
PWA currency converter
3D models for printing
Sources of ruslan.ibragimov.by
push eventJetBrains/kotlin-web-site
commit sha 7786baa233af7b07dadfd58ec5a65181c293df1b
update: updated Kotlin Roadmap (#2014) * Updated the roadmap as of January 2021. * Added a changelog * Moved roadmap notes to the bottom, after the roadmap table. * Added a link to the YT board. * Added a TOC.
push time in 2 hours
PR merged JetBrains/kotlin-web-site
- Updated the roadmap as of January 2021.
- Added a changelog
- Moved roadmap notes to the bottom, after the roadmap table.
- Added a link to the YT board.
- Added a TOC.
pr closed time in 2 hours
push eventJetBrains/kotlin-web-site
commit sha 736f5a7cbd017b946f6c1682658a5e55e17e5484
chore: text edits
push time in 3 hours
fork akuleshov7/diKTat
Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
fork in 3 hours
push eventJetBrains/kotlin-web-site
commit sha f7a81a7c3436181d60575a5a611161df44323f7f
chore: text edits
push time in 3 hours
startedJakeWharton/dockerfile-shebang
started time in 3 hours
issue commentKotlin/KEEP
I would like to pitch for some random sampling methods such as
fun <E> List<E>.sampleRandom(random: Random = DefaultRandom): E fun <E> List<E>.sampleRandomList(size: Int, random: Random = DefaultRandom): List<E> fun <E> List<E>.sampleRandomSet(size: Int, random: Random = DefaultRandom): Set<E> fun <E> List<E>.sampleRandomSet(size: Int, weights: List<Int> = LazyList(this.size) {i -> 1}): Set<E>
The benefit of having such functions in the stdlib is preventing developers from implementing naive-but-incorrect implementations themselves. For example, for
sampleRandomList
it could be tempting to do something like the following, which is incorrect because the result has a different distribution than initialRandom.nextInt()
fun <E> List<E>.sampleRandomList(sampleSize: Int): List<E> { val selectedIndices = mutableSetOf<Int>() repeat(sampleSize) { do { val i: Int = Random.nextInt(indices) val wasNew = selectedIndices.add(i) } while(!wasNew) } return this.slice(selectedIndices) }
Another inefficient approach could be the implementation below, which is very easy to implement with the current proposal, and thus even more probable to be a source of problems.
fun <E> List<E>.sampleRandomList(sampleSize: Int): List<E> = shuffled().take(sampleSize)
As far as I understand, one of the correct and efficient algorithms for sampling is "Vose's Alias" algorithm, of which I am frankly totally ignorant, but you can read about it here http://www.keithschwarz.com/darts-dice-coins/
Can you please explain, why the two methods you present for taking random samples are "naive-but-incorrect"? "Vose's Alias" which you cited is an algorithm for getting random numbers with a biased (non-uniform) distribution. I cannot see how this fits into your example.
comment created time in 4 hours
issue commentKotlin/kotlinx.coroutines
Flow.collect doesn't receive any values
Is there any chance to reproduce with some self-contained code?
comment created time in 4 hours
push eventKotlin/kotlinx.coroutines
commit sha 7548b83f0694ea30331fee296b2dfcd0c143c36b
Clarify yield documentation (#2466) Fixes #2464
push time in 4 hours
pull request commentKotlin/kotlinx.coroutines
👍 Nice clarification. Thanks.
comment created time in 4 hours
issue commentKotlin/kotlinx.coroutines
Thread switching and interoperability using rxSingle wrapper
Interesting. I actually haven't considered that as I initially dismissed that dispatcher thinking that Unconfined refers to unconfined thread pool, i.e. a dispatcher that creates threads as needed instead of using a thread pool. Now that you pointed this out, I read the docs and I can see it's something completely different. This might be exactly the solution I was looking for.
comment created time in 11 hours
issue commentKotlin/kotlinx.coroutines
Thread switching and interoperability using rxSingle wrapper
Have you considered explicitly using rxSingle(Dispatchers.Unconfined)
in order to let rxSingle
continue using the thread provided by the Rx Scheduler
?
comment created time in 11 hours
issue openedKotlin/kotlinx.coroutines
Thread switching and interoperability using rxSingle wrapper
I'm trying to interop Kotlin Flow with RxJava callers using kotlin-coroutines-rx2. All my consumers of the API are currently RxJava chains, which I'm planning to slowly migrate to coroutines. However, my data is exposed as Flow<T>
that needs to be consumed by these Rx chains. The data is coming from Jetpack DataStore. I'm using coroutines-rx2 rxSingle
to wrap the flow into a Single in order to satisfy the caller dependencies. I end up with a function like this:
override fun getData(): Single<Data> = rxSingle { dataStore.data.first() }
Which gets called from chains like this:
repository.getData()
.flatMap { someNetworkCall(it) }
.subscribeOn(schedulerProvider.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ processResult(it) }, { processError(it) })
The threading of this looks like:
getData()
is called on a background thread from Schedulers IOrxSingle
doesn't have a coroutine context and therefore the dispatcher defaults to DefaultDispatchersomeNetworkCall
now runs on the DefaultDispatcher instead of the IO, which would be expected by just reading the Rx chain
In my app, all the threading is at the top layer, where the subscribe is called. This thread switching that rxSingle does is not obvious to whoever's working with the API, and the thread injected and used in bottom layer where getData
exists, might not satisfy the remaining of the Rx chain.
I'm not sure why rxSingle
switches the thread context instead of using the one currently specified by the Rx scheduler, there's probably a good reason for it, but as I see it, my options for this are:
-
Each time I'm using
rxSingle
to wrap a Flow, I can finish with switching the thread using.observeOn()
. This doesn't really satisfy the requirement of being transparent to the caller of the function, as I will just default to an arbitrary thread i decide on, which most likely going to beobserveOn(schedulers.io())
to be safe. So the same getData will look likeoverride fun getData(): Single<Data> = rxSingle(backgroundDispatcher) { dataStore.data.first() }.observeOn(schedulers.io())
-
Or I pass down a dispatcher to use from the Rx chain caller like
repository.getData(schedulers.io().asCoroutineDispatcher())
and pass it to myrxSingle
wrapping function:override fun getData(dispatcher: Dispatcher): Single<Data> = rxSingle(dispatcher) { dataStore.data.first() }
Both options are not great so I'm looking for some advice, maybe I'm missing something here?
created time in 12 hours
PR opened KotlinBy/awesome-kotlin
Checklist:
- [X] Is this pull request against the branch
main
?
pr created time in 13 hours
push eventJetBrains/kotlin-web-site
commit sha 205983343ca2433b4389e47eb37725525cbc6cb7
chore: text edits
push time in 16 hours
startedhyperion-project/hyperion.ng
started time in 19 hours
startedKotlin-Polytech/KotlinAsFirst2020
started time in 19 hours
startedKonloch/bytecode-viewer
started time in 20 hours
push eventKotlin/kotlinx.coroutines
commit sha ba87db30686e5c55be9ea200c758cb14db51b889
[native-mt] Fix the errornous isDispatchNeeded check in Dispatchers.Main.immediate on Darwin platforms. (#2476) Fixes #2283
push time in 20 hours
PR merged Kotlin/kotlinx.coroutines
Resolves https://github.com/Kotlin/kotlinx.coroutines/issues/2283
First commit includes a test case that fails in both macosx64 background & main tests.
pr closed time in 20 hours
push eventKotlin/kotlinx.coroutines
commit sha cb19b9a88fb1a7b5f37e4c88cc3c6ecf13fc49ff
[native-mt] Fix ObjC autorelease object leaks with native-mt dispatchers (#2477) Fixes #2322
push time in 20 hours
PR merged Kotlin/kotlinx.coroutines
Resolves #2322
While 1.4.30-M1 fixed Worker.execute()
leaking ObjC autoreleasing objects when running native code on a K/N Worker thread (KT-42822), it does not address the issue at KoltinX Coroutines framework level.
More specifically, when tasks on an EventLoop call into native code, any autoreleasing object — especially many ObjC method return values — is effectively leaked <sup>[1]</sup>. This is because the first available autoreleasepool in the call stack is in workerMain()
, and it wraps around a most likely never-returning <sup>[2]</sup> runEventLoop()
.
This PR introduced a failing test case of this bug, and fixed it by wrapping all Runnable.run()
calls in EventLoopImplBase
with an autoreleasepool (or nothing for non-Darwin targets). This is equivalent to the DISPATCH_AUTORELEASE_FREQUENCY_WORK_ITEM<sup>[3]</sup> in GCD.
An alternative to the per-item wrapping is integrating pool push/pop into runEventLoop()
, with heruistics based on the park time returned by processNextEvent()
. Not familiar enough about the particulars to try this out though.
<sup>[1]</sup> ... unless an autoreleasepool is declared in user code explicitly, which is a rare practice except for memory optimization.
<sup>[2]</sup> Dispatchers.Default
, for example.
<sup>[3]</sup> ... which is not the default behaviour. GCD threads inherit autorelease pool management from NSRunLoop
, which recreates pools for each runloop iteration.
pr closed time in 20 hours