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 { factorizeType } from "./SumType.js";
export const IO = factorizeType("IO", [ "asyncFunction" ]);
IO.empty = _ => IO(_ => null);IO.from = (composedFunction) => IO(composedFunction);IO.of = value => IO(_ => value);
// ap :: IO a ~> IO (a -> b) -> IO bIO.prototype.ap = IO.prototype["fantasy-land/ap"] = function (container) {
return container.map(unaryFunction => unaryFunction(this.asyncFunction()));};
// chain :: IO a ~> (a -> IO b) -> IO bIO.prototype.chain = IO.prototype["fantasy-land/chain"] = function (unaryFunction) {
return IO(_ => unaryFunction(this.asyncFunction())).run();};
// map :: IO a ~> (a -> b) -> IO bIO.prototype.map = IO.prototype["fantasy-land/map"] = function (unaryFunction) {
return IO(_ => unaryFunction(this.asyncFunction()));};
// run :: IO a ~> () -> bIO.prototype.run = function () {
return this.asyncFunction();};
export default IO;