From 6da602b0a29afcd2aa15725547375a80e30b3983 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 27 Nov 2024 02:12:12 +0100 Subject: initial commit --- src/state.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/state.js (limited to 'src/state.js') diff --git a/src/state.js b/src/state.js new file mode 100644 index 0000000..8db6be4 --- /dev/null +++ b/src/state.js @@ -0,0 +1,15 @@ +import * as wrapper from "./wrapper.js" + +export const State = v => st => s => s(st)(v) + +export const get = st => s => s(st)(st) +export const put = _st => st => s => s(_st)() +export const modify = f => st => s => s(f(st))() + +export const fmap = f => g => st0 => g(st0)(st1 => a => s => s(st1)(f(a))) +export const ap = f0 => x0 => st0 => f0(st0)(st1 => f1 => x0(st1)(st2 => x1 => s => s(st2)(f1(x1)))) + +export const unit = State +export const bind = run => f => s0 => run(s0)(s1 => v => f(v)(s1)) + +export const DO = wrapper.DO(unit, bind) -- cgit v1.2.3