import { todo } from './todo.js' /** @import { State } from './types' */ /** * Optional (Exercise 4.7). A `State` is a plain function from a state to a pair: `s => [value, nextS]`. * It is `Random` with the seed replaced by any state type `S`. Nothing in the game uses this file. */ /** A State that gives `a` and leaves the state untouched: `s => [a, s]`. * @type {(a: A) => State} */ export const pure = (a) => todo('m04') /** Transform the value a State produces; the state threading is unchanged. * @type {(st: State, f: (a: A) => B) => State} */ export const map = (st, f) => todo('m04') /** Run `st`, feed its value to `f` to pick the next State, and run that with the state `st` left behind. * @type {(st: State, f: (a: A) => State) => State} */ export const flatMap = (st, f) => todo('m04') /** A State whose value is the current state, which it leaves untouched: `s => [s, s]`. (A value, not a function call.) * @type {(s: S) => [S, S]} */ export const get = (s) => todo('m04') /** A State that replaces the state with `s` and gives `undefined`: whatever the old state, `[undefined, s]`. * @type {(s: S) => State} */ export const put = (s) => todo('m04') /** A State that replaces the state `s` with `f(s)` and gives `undefined`. * @type {(f: (s: S) => S) => State} */ export const modify = (f) => todo('m04') /** Run a State from an initial state: `[value, finalState]`. * @type {(st: State, s: S) => [A, S]} */ export const run = (st, s) => todo('m04')