Skip to content

Instantly share code, notes, and snippets.

View rlmark's full-sized avatar

Rebecca rlmark

  • Unison Computing
  • Seattle, Washington
View GitHub Profile
@bond15
bond15 / FibHist.hs
Last active November 4, 2022 15:42
Fibonacci Histomorphism
module Fib where
import Control.Arrow((>>>),(&&&))
import Control.Comonad.Cofree
newtype Fix f = In { out :: (f (Fix f) ) }
data NatF a = Z | S a deriving Show
-- Peano natural numbers as the least fixed point of functor NatF
type Nat = Fix NatF
@Daenyth
Daenyth / MonadAndFs2Ops.md
Last active June 25, 2024 13:04
Cheat sheet for common cats monad and fs2 operation shapes
Operation Input Result Notes
map F[A] , A => B F[B] Functor
apply F[A] , F[A => B] F[B] Applicative
(fa, fb, ...).mapN (F[A], F[B], ...) , (A, B, ...) => C F[C] Applicative
(fa, fb, ...).tupled (F[A], F[B], ...) F[(A, B, ...)] Applicative
flatMap F[A] , A => F[B] F[B] Monad
traverse F[A] , A => G[B] G[F[A]] Traversable; fa.traverse(f) == fa.map(f).sequence; "foreach with effects"
sequence F[G[A]] G[F[A]] Same as fga.traverse(identity)
attempt F[A] F[Either[E, A]] Given ApplicativeError[F, E]
public void stutter(ArrayList<String> list) {
int l = list.size();
// seed
for (int i = 0; i < l; i++){
list.add("");
}
// work backwards
int f = list.size() - 1;
for (int i = l - 1; i >= 0; i--){
String temp = list.get(i);
@veryphatic
veryphatic / markov.java
Created July 27, 2012 23:11
Simple Markov chain text generator
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;
public class Markov {