Skip to main content
Module

x/functional/IO.js

Common Functional Programming Algebraic data types for JavaScript that is compatible with most modern browsers and Deno.
Go to Latest
File
import { assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
import { assertIsDefined, assertIsEquivalent, assertIsNone } from "./asserts.js";import { factorizeSumType } from "./SumType.js";
export const IO = factorizeSumType( "IO", { Nothing: [], Just: [ "asyncFunction" ] });
IO.from = (composedFunction) => IO(composedFunction);IO.of = value => IO(() => value);
// chain :: IO a => a ~> (a -> b) -> bIO.prototype.chain = function (composedFunction) {
return composedFunction(this.asyncFunction);};
// map :: IO a => a ~> (a -> b) -> IO bIO.prototype.map = function (composedFunction) {
// Have to handle #catch, ideally without entangle with Response.`error` return IO(() => composedFunction(this.asyncFunction()));};
// run :: IO a => a ~> () -> Promise bIO.prototype.run = function () {
return this.asyncFunction();};