Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Raúl Raja Martínez raulraja

View GitHub Profile
@raulraja
raulraja / ErrorHandling.kt
Created January 1, 2023 14:02
Error Handling Evolution with Arrow 2.0.
package demo
import arrow.core.Either
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.continuations.Raise
import arrow.core.continuations.effect
import arrow.core.continuations.either
import arrow.core.continuations.toEither
@raulraja
raulraja / 0.SIP.md
Last active July 8, 2022 18:19
Scala 3 Continuations

Pre-SIP: Suspended functions and continuations in Scala 3.

This Pre-SIP post proposes continuations as a new language feature in Scala 3.

It has been prepared by Jack Viers, Raul Raja and reviewed by the Scala 3 team at 47 Degrees. This doc is intended to be used as a way to gather community feedback and foster discussion.

Motivation

Our observation in the industry and among our peers is that most programming in Scala today that involves async or I/O-based programs targets a monadic indirect boxed style.

package org.coral.fp.control
import arrow.core.ValidatedNel
import arrow.core.invalidNel
import arrow.core.validNel
import arrow.core.zip
import kotlin.jvm.JvmInline
@JvmInline
public value class ProductId private constructor(public val value: Int) {
@raulraja
raulraja / pipe.kt
Created March 1, 2022 11:17
EffectScope pipe
package examples
import arrow.core.Either
import arrow.core.continuations.EffectScope
import arrow.core.continuations.either
object Request
object Response
sealed interface Error
object InvalidRequest : Error
@raulraja
raulraja / PartiallyAppliedFn.kt
Created December 22, 2021 21:54
Partially applied functions with selective arg application
package arrow.core
public fun interface Partial<A, B, C, D, Z> {
public operator fun invoke(a: A, b: B, c: C, d: D): Z
public fun first(a: A): Partial<Unit, B, C, D, Z> =
Partial { _, b, c, d -> invoke(a, b, c, d) }
public fun second(b: B): Partial<A, Unit, C, D, Z> =
Partial { a, _, c, d -> invoke(a, b, c, d) }
@raulraja
raulraja / Services.kt
Last active December 28, 2021 21:37
Services as composable suspended functions
package arrow.meta.continuations
import arrow.core.Either
import arrow.core.computations.either
import arrow.core.flatMap
/**
* Models errors as values
*/
sealed interface Failure
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 June 6, 2021 09:33
Given validation steps

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 17:30
Constraint ADT for Flow Action and Reaction emit
/** 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]
*/
package dbactions
import arrow.continuations.Effect
import arrow.continuations.generic.DelimitedScope
import kotlin.reflect.KClass
/**
* An abstract connection
*/
interface Connection {