This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ComonadKleisli where | |
import Data.Maybe | |
import Data.List | |
import Control.Monad | |
fmapM :: (a -> Maybe b) -> [a] -> Maybe [b] | |
fmapM f = Just . catMaybes . fmap f | |
duplicateM :: [a] -> Maybe [[a]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test where | |
import Prelude | |
import Data.Lens (Lens, _Just, lens, (.~)) | |
import Data.Maybe (Maybe(..)) | |
import Effect.Exception.Unsafe (unsafeThrow) | |
data CRUD a | |
= Create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE | |
KindSignatures | |
, DataKinds | |
, RankNTypes | |
, GADTs | |
, TypeFamilies | |
, TypeFamilyDependencies | |
, ScopedTypeVariables | |
, TypeApplications | |
, ViewPatterns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE | |
RankNTypes, | |
TypeApplications, | |
TypeOperators, | |
KindSignatures, | |
TypeFamilies, | |
TypeInType, | |
MultiParamTypeClasses, | |
FunctionalDependencies, | |
FlexibleInstances, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE ViewPatterns #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Main where | |
import Prelude as P |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: :: morphism c = c -> c -> * | |
:: :: morphism c -> * | |
:: category p = | |
:: { id: p a a, compose: p b c -> p a b -> p a c } | |
:: :: (c -> d) -> morphism c -> morphism d -> * | |
:: functor f i o = | |
:: { map: i a b -> o (f a) (f b) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { adt, match, otherwise } = require("@masaeedu/adt"); | |
const { | |
Obj, | |
Fn, | |
Arr, | |
Cont, | |
implement, | |
Functor, | |
Apply, | |
Chain, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This gist shows how to factor a concrete stateful fold in vanilla JS | |
// into a number of general purpose utilities that can be combined to recover | |
// the original behavior | |
// We're going to start from a particular code snippet and iteratively make | |
// small changes to it to get a finished product | |
// While reading this post, it is useful to have a diff tool at hand that allows | |
// you to compare snippets side by side and see what changed in each iteration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Utils | |
const range = n => [...Array(n).keys()]; | |
const add = ([x0, y0]) => ([x1, y1]) => [x0 + x1, y0 + y1]; | |
const rotate = θ => ([x, y]) => [ | |
Math.round(x * Math.cos(θ) - y * Math.sin(θ)), | |
Math.round(x * Math.sin(θ) + y * Math.cos(θ)) | |
]; | |
const map = f => g => | |
function*() { | |
for (const v of g()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { mdo } = require("@masaeedu/do"); | |
const { | |
Obj, | |
Fn, | |
Fnctr, | |
ReaderT, | |
Reader, | |
StateT, | |
State | |
} = require("@masaeedu/fp"); |