Generated by AVA.
Snapshot 1
[
1,
-1,
]Snapshot 2
[
0,
1,
]| // Functor | |
| export const map = f => s => x0 => { | |
| const [v, x1] = s(x0); | |
| return [f(v), x1]; | |
| }; | |
| // Applicative | |
| export const pure = a => x => [a, x]; | |
| export const ap = stf => stv => x0 => { | |
| const [f, x1] = stf(x0); | |
| const [v, x2] = stv(x1); | |
| return [f(v), x2]; | |
| }; | |
| // Monad | |
| export const chain = f => s => x0 => { | |
| const [v, x1] = s(x0); | |
| return f(v)(x1); | |
| }; |
| import test from "ava"; | |
| import * as State from "../state"; | |
| test("monad", t => { | |
| // Flip flop between incrementing and decrementing | |
| const transition = State.chain(v => x => [v + x, x * -1]); | |
| const start = State.pure(0) | |
| t.snapshot(1 |> (start |> transition)); | |
| t.snapshot(1 |> (start |> transition |> transition)); | |
| }); |
Generated by AVA.
Snapshot 1
[
1,
-1,
]Snapshot 2
[
0,
1,
]