Skip to content

Instantly share code, notes, and snippets.

View mayojava's full-sized avatar

Mayowa Adegeye mayojava

View GitHub Profile
package dev.efemoney.orchestra.ui
import androidx.compose.animation.asDisposableClock
import androidx.compose.animation.core.AnimationClockObservable
import androidx.compose.animation.core.TargetAnimation
import androidx.compose.animation.core.tween
import androidx.compose.foundation.animation.AndroidFlingDecaySpec
import androidx.compose.foundation.animation.FlingConfig
import androidx.compose.foundation.gestures.ScrollableController
import androidx.compose.foundation.gestures.scrollable
@mayojava
mayojava / flow_merge.kt
Created April 12, 2019 15:05
What a mergeWith Flow operator might look like
@FlowPreview
fun <T> Flow<T>.mergeWith(other: Flow<T>): Flow<T> = flow {
coroutineScope {
launch {
other.collect {
emit(it)
}
}
launch {
@mayojava
mayojava / competitions.xml
Last active December 4, 2018 07:17
home_fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="320dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.Guideline android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/left_guide"
@mayojava
mayojava / sample_presenter_fetch.kt
Created November 17, 2018 14:33
coroutine demonstration
class CoroutinesPresenter(private val dispatcherProvider: DispatchersProvider,
private val repository: Reviewsrepository) {
private val job = Job()
private val uiScope = CoroutineContext(dispatcherProvider.main + job) //runs on main thread
fun fetchData(count: Int, page: Int) {
try {
uiScope.launch {
arbitraryView.setLoading(true)
@mayojava
mayojava / actor.kt
Created November 7, 2018 18:57
actor coroutine builder
public fun <E> CoroutineScope.actor(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0,
start: CoroutineStart = CoroutineStart.DEFAULT,
onCompletion: CompletionHandler? = null,
block: suspend ActorScope<E>.() -> Unit
): SendChannel<E>
@mayojava
mayojava / produce_sample.kt
Last active November 7, 2018 18:56
Produce builder sample
fun main() = runBlocking {
val multiplesOfThree = produce {
(1..10).filter {
it % 3 == 0
}.forEach {
send(it) //send can only be called inside the ProducerScope
}
}
@mayojava
mayojava / produce.kt
Created November 7, 2018 18:54
Produce Coroutine Builder
public fun <E> CoroutineScope.produce(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0,
block: suspend ProducerScope<E>.() -> Unit
): ReceiveChannel<E>
@mayojava
mayojava / broadcastChannel.kt
Created November 7, 2018 18:54
BroadcastChannel does not suspend
fun main() = runBlocking {
val channel = BroadcastChannel<Int>(1)
repeat(10) {
channel.send(it)
}
}
@mayojava
mayojava / conflated_channel.kt
Created November 7, 2018 18:52
Conflated BroadcastChannel
fun main() = runBlocking<Unit> {
val channel = ConflatedBroadcastChannel<Int>()
launch {
channel.consumeEach {
println("first: $it")
delay(500)
}
}
@mayojava
mayojava / channel_consumed_once.kt
Created November 7, 2018 18:47
Consuming a channel once
fun main() = runBlocking {
val channel = Channel<Int>()
launch {
repeat(5) {
channel.send(it*it)
}
channel.close()
}
println("begin")