Skip to content

Instantly share code, notes, and snippets.


Gabriel Volpe gvolpe

Block or report user

Report or block gvolpe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
gvolpe / raceN.scala
Created Dec 13, 2019 — forked from ChristopherDavenport/raceN.scala
An Implementation of a Safe Multi-value Race
View raceN.scala
object RaceN {
import cats.implicits._
import cats.effect._
import cats.effect.concurrent._
// Use with atleast 3, otherwise you should prefer Concurrent.race
def raceN[F[_]: Concurrent, A](x1: F[A], x2: F[A], x3: F[A], xs: F[A]*): F[Either[NonEmptyList[Throwable], A]] = {
for {
deferred <- Deferred[F, A]
gvolpe / RefMap.scala
Created Nov 22, 2019 — forked from johnynek/RefMap.scala
A wrapper on ConcurrentHashMap to use with cats.effect.Ref
View RefMap.scala
package org.bykn.refmap
import cats.effect.Sync
import cats.effect.concurrent.Ref
import java.util.concurrent.ConcurrentHashMap
import cats.implicits._
View simple-refined-email.scala
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.string.MatchesRegex
object refinements {
type EmailPred = MatchesRegex[W.`"""(?=[^\\s]+)(?=(\\w+)@([\\w\\.]+))"""`.T]
type Email = String Refined EmailPred
View init.vim
set directory=~/.vim/backup
set backupdir=~/.vim/backup " keep swap files here
filetype off " required
call plug#begin('~/.local/share/nvim/plugged') " you need to create this directory first (or change it)
Plug 'vim-airline/vim-airline' " bottom status bar
Plug 'vim-airline/vim-airline-themes'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " fuzzy finder conf
Plug 'junegunn/fzf.vim' " fuzzy finder
gvolpe / OpClasses.idr
Created Aug 21, 2019 — forked from sellout/OpClasses.idr
Defining ad-hoc polymorphism using dependently-typed implicits.
View OpClasses.idr
-- This illustrates (most of) a new(?) encoding of ad-hoc polymorphism using
-- dependent types and implicits.
-- Benefits of this approach:
-- • can have multiple “ambiguous” instances without requiring things like
-- Haskell’s newtypes to distinguish them;
-- • can disambiguate instances with minimal information, rather than having to
-- know some arbitrary instance name as you would with a system like Scala’s
-- implicits;
-- • implementers don’t need to know/provide the full family of instances – they
gvolpe / sharding-fs2.scala
Last active May 24, 2019
Sharding values using Fs2
View sharding-fs2.scala
import cats.effect._
import cats.effect.concurrent.Ref
import cats.implicits._
import fs2._
import fs2.concurrent.Queue
import scala.util.control.NoStackTrace
object ShardingDemo extends IOApp {
def putStrLn[A](a: A): IO[Unit] = IO(println(a))
gvolpe /
Created Apr 16, 2019 — forked from Daenyth/
CachedResource for cats-effect


cats-effect Resource is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:

trait Resource[F[_], A] {
  /** - Acquire resource
    * - Run f
    * - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails
  def use[B](f: A => F[B]): F[B]
View flip-andThen.hs
flip' :: (a -> b -> c) -> b -> a -> c
flip' f b a = f a b
andThen :: (a -> b) -> (b -> c) -> a -> c
andThen = flip' (.)
View function-composition.scala
// (.) :: (b -> c) -> (a -> b) -> a -> c
implicit class FancyComposition[A, B, C](f: B => C) {
def `.`(g: A => B): A => C = f.compose(g)
val f: Int => String = _.toString
val g: String => Boolean = _.contains("1")
val h: Int => Boolean = g `.` f
gvolpe /
Created Jan 31, 2019 — forked from smarter/
GADTs in Scala

Generalized Algebraic Data Types in Scala

Basic GADTs

Here's an ADT which is not a GADT, in Haskell:

data Expr = IntExpr Int | BoolExpr Bool
You can’t perform that action at this time.