Skip to content

Instantly share code, notes, and snippets.

Raúl Raja Martínez raulraja

View GitHub Profile
@raulraja
raulraja / 0.SIP.md
Last active Jul 8, 2022
Scala 3 Continuations
View 0.SIP.md

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.

View Issue2689.kt
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 Mar 1, 2022
EffectScope pipe
View pipe.kt
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 Dec 22, 2021
Partially applied functions with selective arg application
View PartiallyAppliedFn.kt
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 Dec 28, 2021
Services as composable suspended functions
View Services.kt
package arrow.meta.continuations
import arrow.core.Either
import arrow.core.computations.either
import arrow.core.flatMap
/**
* Models errors as values
*/
sealed interface Failure
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>() {