Skip to content

Instantly share code, notes, and snippets.

Variants

Author

  • Alejando Serrano (47 Degrees)

Champions

  • Searching for one ;)
@DrBoolean
DrBoolean / three_envs.js
Last active May 24, 2021 02:31
Tail of three envs
const compose = (f, g) => x => f(g(x))
const Id = x =>
({
fold: f => f(x),
map: f => Id(f(x))
})
Id.of = Id
const Tuple = (_1, _2) =>
@MarkusPfundstein
MarkusPfundstein / prod_comonad.js
Last active May 25, 2018 10:38
Product Comonad example
const Prod = t => ({
extract : () => t[1],
extend : f => Prod([t[0], f([t[0], t[1]])]),
map : f => Prod([t[0], f(t[1])]),
duplicate : () => Prod([t[0], Prod(t)])
});
@dead-claudia
dead-claudia / composition-proposal.md
Last active June 2, 2017 17:36
Function Composition Strawman
@myuon
myuon / Main.hs
Last active June 17, 2019 18:29
Lens from Scratch
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, Rank2Types #-}
import Control.Applicative
import Control.Monad
import Data.Functor.Identity
import Data.Foldable
import Data.Monoid
import Data.Tagged
class Profunctor p where
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
@ion1
ion1 / MiniLens.hs
Last active June 16, 2019 06:00
Mini lens
{-# LANGUAGE RankNTypes #-}
import Control.Applicative
import Data.Functor.Identity
import Data.Monoid
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
_1 :: Lens (a,b) (a',b) a a'
@divarvel
divarvel / continuation.js
Last active May 27, 2023 08:12
implementation of the continuation monad in JS
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof actual === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
@tel
tel / ParserCombinators.hs
Created November 3, 2014 19:54
Monad transformers and parser combinators
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module ParserCombinators where
{-
We'll build a set of parser combinators from scratch demonstrating how
they arise as a monad transformer stack. Actually, how they arise as a
choice between two different monad transformer stacks!