Skip to content

Instantly share code, notes, and snippets.

View nomisRev's full-sized avatar
🏂

Simon Vergauwen nomisRev

🏂
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nomisRev
nomisRev / KGraphQLServer.kt
Created March 14, 2025 08:29
Ktor Koin KGraphQL
import com.apurebase.kgraphql.GraphQL
import com.apurebase.kgraphql.schema.Publisher
import com.apurebase.kgraphql.schema.dsl.SchemaBuilder
import io.ktor.server.application.*
import org.koin.dsl.module
import org.koin.ktor.ext.inject
import org.koin.ktor.plugin.Koin
import org.koin.logger.slf4jLogger
import kotlin.getValue
package io.github.nomisrev
import app.cash.sqldelight.driver.jdbc.asJdbcDriver
import arrow.continuations.SuspendApp
import arrow.continuations.ktor.server
import arrow.fx.coroutines.autoCloseable
import arrow.fx.coroutines.closeable
import arrow.fx.coroutines.resourceScope
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
@nomisRev
nomisRev / AutoClose.kt
Last active July 19, 2023 13:03
A Kotlin DSL for AutoCloseable
import arrow.atomic.Atomic
import arrow.atomic.update
/**
* AutoClose offers DSL style API for creating parent-child relationships of AutoCloseable dependencies
*/
interface AutoClose : AutoCloseable {
fun <A : AutoCloseable> autoClose(autoCloseable: A): A
}
@nomisRev
nomisRev / Example.kt
Created April 10, 2023 16:55
StackOverflow Question
import arrow.core.Nel
import arrow.core.raise.Raise
import arrow.core.raise.recover
import arrow.fx.coroutines.parZipOrAccumulate
object ApplicationError
object UserLegalId
object User
object DepartmentCode
object Department
@nomisRev
nomisRev / Racers.kt
Last active February 27, 2023 19:15
POC Race Design
sealed interface RaceRes<A, B>
data class First<A>(val first: A): RaceRes<A, Nothing>
data class FirstWithFailure<A>(val first: A, val second: Throwable): RaceRes<A, Nothing>
data class Second<B>(val second: B): RaceRes<Nothiing, B>
data class SecondWithFailure<B>(val first: Throwable, val second: B): RaceRes<Nothing, B>
/**
* raceSuccess({ req(0) }) { req(0) }).merge()
* What to do with exceptions?? RaceRes seems very clumsy.
*/
@nomisRev
nomisRev / README.MD
Last active August 28, 2023 06:43
Migration script for Arrow 1.2.0 to migrate towards arrow.core.raise.*

Arrow 1.2.0 Raise migration script

This migration script attempts to automatically migrate arrow.core.computations.* and arrow.core.continuations.* on a best effort to arrow.core.raise.*. It has been tested on serveral real-life projects with 100% success, being able to automatically migrate the entire codebase.

The run this kts script you need kotlinc install on your machine. The official documentation on how to install kotlinc.

Some methods like ensure in the DSL became top-level, and fold if you're using Effect or EagerEffect. These new top-level imports cannot be automatically migrated, and there are two ways of dealing with the necessary imports.

@nomisRev
nomisRev / TimedDSL.kt
Last active December 20, 2022 10:46
TimedDSL
import arrow.core.continuations.AtomicRef
import arrow.core.continuations.update
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimedValue
import kotlin.time.measureTimedValue
@OptIn(ExperimentalTime::class)
class TimedDSL {
val total: AtomicRef<Duration> = AtomicRef(Duration.ZERO)
@nomisRev
nomisRev / Timed.kt
Created September 21, 2022 07:19
Timed Value monad.
public interface Timed<A> {
public fun result(): A
public fun startMs(): Long
public fun endMs(): Long
}
// Add strategies as needed
public enum class TimedStrategy { EarliestStartAndLatestEnd; }
public interface TimedDSL {
@nomisRev
nomisRev / Console.kt
Created May 23, 2022 15:50
Console Effect handler
import arrow.core.continuations.EffectScope
import arrow.core.continuations.effect
object EndOfLine
interface Console {
context(EffectScope<EndOfLine>)
suspend fun read(): String
suspend fun String.write(): Unit