Skip to content

Instantly share code, notes, and snippets.

Raúl Raja Martínez raulraja

View GitHub Profile
View Derive.kt
package arrow.derive
/**
* An Algebraic data type [Type] can derive behaviors
* for its members
*/
sealed class Derive<in Type> {
/**
* Derived instances associated to [Type]
*/
@raulraja
raulraja / given.md
Last active Jun 6, 2021
Given validation steps
View given.md

Given validation steps

  1. Only top level class, object, property or function can be @Given declarations
@Given fun <T> et(@Given eq: Eq<T>): Eq<Tree<T>> = ...
  1. Declarations with Value parameters annotated as @Given for injection must
@raulraja
raulraja / adt_bound_constrain.kt
Created May 28, 2021
Constraint ADT for Flow Action and Reaction emit
View adt_bound_constrain.kt
/** Dummy login model **/
@JvmInline
value class UserName(val value: String)
@JvmInline
value class Password(val value: String)
/**
* A [Reaction] is always parametric to a type of [Action]
*/
View DBEffect.kt
package dbactions
import arrow.continuations.Effect
import arrow.continuations.generic.DelimitedScope
import kotlin.reflect.KClass
/**
* An abstract connection
*/
interface Connection {
@raulraja
raulraja / st.kt
Created Nov 14, 2020
Marco's question in slack
View st.kt
package arrow.prelude.test
import arrow.continuations.generic.DelimContScope
import arrow.continuations.generic.DelimitedScope
abstract class ST<S, A> @PublishedApi internal constructor() {
companion object {
operator fun <S, A> invoke(a: () -> A): ST<S, A> {
val memo by lazy(a)
return object : ST<S, A>() {
@raulraja
raulraja / IO.kt
Created Apr 17, 2020
Kinds without uncheched casts
View IO.kt
/** Bifunctor IO */
class IO<out E, out A> :
`*`<IO<*, *>>,
`*-*`<IO<*, *>, A>,
`*-*-*`<IO<*, *>, E, A> {
fun <B> fmap(f: (A) -> B): IO<Nothing, B> = TODO()
fun <B> flatMap(f: (A) -> `*-*`<IO<*, *>, B>): IO<Nothing, B> = TODO()
fun <C, D> bimap(fl: (E) -> C, fr: (A) -> D): IO<C, D> = TODO()
companion object {
@raulraja
raulraja / AutoCancellation.kt
Last active Mar 8, 2020
Arrow Fx. Auto cancels without leaving to user discipline to check for `isAlive`. Examples by @nomisRev
View AutoCancellation.kt
import arrow.fx.*
import arrow.fx.extensions.*
import arrow.fx.typeclasses.*
import arrow.fx.extensions.io.bracket.guaranteeCase
fun <A> IOOf<A>.onCancel(token: IOOf<Unit>): IO<A> =
guaranteeCase { case ->
when (case) {
ExitCase.Canceled -> token
else -> IO.unit
@raulraja
raulraja / rules.kt
Created Mar 5, 2020
Validation rules abstracting strategies with operations as extension functions
View rules.kt
package arrow.rules.test
import arrow.Kind
import arrow.core.Either
import arrow.core.EitherPartialOf
import arrow.core.Nel
import arrow.core.NonEmptyList
import arrow.core.Validated
import arrow.core.ValidatedPartialOf
import arrow.core.extensions.either.applicativeError.applicativeError
@raulraja
raulraja / TwitterHandle.kt
Created Feb 20, 2020
Type Refinements with Type Proofs in Kotlin
View TwitterHandle.kt
/* Coming up ~ April 2020 */
package test
import arrow.*
inline class TwitterHandle(val handle: String) {
companion object : Refined<String> {
override val validate: String.() -> Map<String, Boolean> = {
mapOf(
"Should start with '@'" to startsWith("@"),
@raulraja
raulraja / prelude.kt
Created Jan 7, 2020
Daydreaming proofs as contracts
View prelude.kt
package arrow.meta.ide.plugins.proofs.contracts
import kotlin.contracts.Effect
import kotlin.contracts.ExperimentalContracts
interface TypeLevelEffect : Effect
interface Declaration : Effect
fun declaration(): Declaration = TODO()