Skip to content

Instantly share code, notes, and snippets.

@colomboe
colomboe / VideoStoreDeclarativeRules.kt
Created June 11, 2020 17:30
Videostore Kata declarative rules
package videostore.declarative
import java.math.BigDecimal
import kotlin.reflect.KProperty
data class Days(val count: Int)
fun Int.days() = Days(this)
fun Int.day() = Days(this)
@colomboe
colomboe / kio-test.kt
Created December 16, 2019 19:03
Porting of "Simple example of testing with ZIO environment" to Kotlin with KIO
// Porting of https://gist.github.com/jdegoes/dd66656382247dc5b7228fb0f2cb97c8
import it.msec.kio.*
import it.msec.kio.common.tuple.T
import it.msec.kio.common.tuple.T2
import it.msec.kio.common.tuple.T3
import it.msec.kio.ref.Ref
import it.msec.kio.result.Failure
import it.msec.kio.result.Result
import it.msec.kio.result.Success
@colomboe
colomboe / FollowedBy.kt
Last active December 6, 2019 08:42
Possible followedBy operator
// followedBy operator definition
@JvmName("pureFollowedByAny")
infix fun <A, B, C> ((A) -> B).followedBy(f: (B) -> C): (A) -> C = { a -> f(this(a)) }
@JvmName("effFollowedByPure")
infix fun <R, E, A, B, C> ((A) -> KIO<R, E, B>).followedBy(f: (B) -> C): (A) -> KIO<R, E, C> = { a -> this(a).map(f) }
@JvmName("effFollowedByEff")
infix fun <R, E, A, B, C> ((A) -> KIO<R, E, B>).followedBy(f: (B) -> KIO<R, E, C>): (A) -> KIO<R, E, C> = { a -> this(a).flatMap(f) }
package experiment
import arrow.Kind
import arrow.core.Either
import arrow.core.Option
import arrow.effects.ForIO
import arrow.effects.IO
import arrow.effects.extensions.fx
import arrow.effects.extensions.io.concurrent.concurrent
import arrow.effects.extensions.io.unsafeRun.runBlocking
@colomboe
colomboe / fx-test.kt
Created July 4, 2019 19:25
Porting of "Simple example of testing with ZIO environment" to Kotlin
// Porting of https://gist.github.com/jdegoes/dd66656382247dc5b7228fb0f2cb97c8
typealias UserID = String
data class UserProfile(val name: String)
// The database module:
interface DatabaseService {
suspend fun dbLookup(id: UserID): UserProfile
suspend fun dbUpdate(id: UserID, profile: UserProfile)
}