Skip to content

Instantly share code, notes, and snippets.

Raúl Raja Martínez raulraja

View GitHub Profile
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverlappingInstances #-}
module Main where
import Control.Monad.Free
@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
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 / 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.

@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 / 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
@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 / di.kt
Last active October 30, 2021 16:30
Simple Kotlin DI
package com.fortyseven.fptraining
import arrow.core.Either
import arrow.core.right
import arrow.effects.IO
import arrow.effects.extensions.io.fx.fx
data class Account(val balance: Int)
data class AccountEntity(val balance: Int)
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