This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.continuations.Effect | |
import arrow.continuations.generic.DelimitedScope | |
import arrow.core.Either | |
import arrow.core.right | |
import com.squareup.sqldelight.TransactionWithReturn | |
import kotlin.coroutines.RestrictsSuspension | |
/** | |
* Either-Syntax for SqlDelight transactions. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class HealthCheck(val heapRead: Long, val heapHit: Long, val ratio: Float) | |
suspend fun DataSource.databaseHealth(): HealthCheck? = | |
connection.use { conn -> | |
conn.createStatement() | |
.executeQuery(healthCheckQuery).use { rs -> | |
if (rs.next()) HealthCheck( | |
rs.getLong("heap_read"), | |
rs.getLong("heap_hit"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sample | |
import arrow.core.* | |
import arrow.core.computations.either | |
import arrow.fx.coroutines.raceN | |
public data class NewsItem(val id: String) | |
public data class Detail(val id: String, val content: String) | |
public object Failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.core.Either | |
import arrow.core.computations.EitherEffect | |
import arrow.core.computations.either | |
suspend fun <E> EitherEffect<E, *>.require(test: Boolean, fail: () -> E): Unit = | |
if (test) Unit | |
else Either.Left(fail()).bind() | |
suspend fun <E> EitherEffect<E, *>.error(error: E): Unit = | |
Either.Left(error).bind() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.fx.coroutines.CancelToken | |
import arrow.fx.coroutines.SuspendConnection | |
import arrow.fx.coroutines.cancellable | |
import java.util.concurrent.CancellationException | |
import java.util.concurrent.CompletableFuture | |
import java.util.concurrent.CompletionException | |
import java.util.concurrent.CompletionStage | |
import java.util.concurrent.ExecutionException | |
import java.util.concurrent.Future | |
import kotlin.coroutines.Continuation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package arrow.fx.coroutines | |
import arrow.fx.coroutines.Queue.BackpressureStrategy | |
import arrow.fx.coroutines.Queue.BackpressureStrategy.* | |
/** | |
* [Dequeue] allows peeking and taking values from a [Queue], but doesn't allow offering values to the [Queue]. | |
* You can use [Dequeue] to restrict certain functions or layers of your applications to only consume values. | |
* | |
* ```kotlin:ank:playground |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.core.* | |
import memeid.UUID | |
data class User(val email: String, val name: String) { | |
companion object | |
} | |
data class ProcessedUser(val id: UUID, val email: String, val name: String) { | |
companion object | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.fx.extensions.io.applicative.map | |
import arrow.fx.extensions.io.monad.flatMap | |
import arrow.fx.extensions.io.monadDefer.monadDefer | |
import java.lang.RuntimeException | |
| |
enum class CBState { | |
CLOSED, OPEN, DISABLED; | |
} | |
| |
class CallNotPermitedException(val state: CBState): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.fx.IO | |
import arrow.fx.extensions.fx | |
fun chunks(): List<List<String>> = listOf( | |
listOf("a", "b", "c"), | |
listOf("d", "e", "g") | |
) | |
fun process(prevChunks: List<String>, rest: List<List<String>>, merged: List<String>, size: Int, max: Int): IO<List<String>> = | |
if (size == max) IO.just(merged) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.Kind | |
import arrow.fx.ForIO | |
import arrow.fx.IO | |
import arrow.fx.IOOf | |
import arrow.fx.Queue | |
import arrow.fx.extensions.fx | |
import arrow.fx.extensions.io.concurrent.concurrent | |
import arrow.fx.extensions.io.dispatchers.dispatchers | |
import arrow.fx.fix | |
import arrow.fx.typeclasses.Concurrent |