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] |
This file contains 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 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 |
This file contains 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
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); |
This file contains 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
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 { |