Skip to main content
Module

x/functional/library/IO.js>default

Common Functional Programming Algebraic data types for JavaScript that is compatible with most modern browsers and Deno.
Latest
variable default
import { default } from "https://deno.land/x/functional@v1.3.4/library/IO.js";

IO

The IO type represents a call to IO. Any Functional Programming purist would tell you that your functions has to be pure... But in the real world, this is not very useful. Wrapping your call to IO with IO will enable you to postpone the side-effect and keep your program (somewhat) pure.

The IO type implements the following algebras:

  • [x] Monad

Example

import IO from "https://deno.land/x/functional@v1.3.2/library/IO.js";

const container = IO(_ => readFile(`${Deno.cwd()}/dump/hoge`))
  .map(promise => promise.then(text => text.split("\n")));
// File isn't being read yet. Still pure.

assert(IO.is(containerA));

const promise = container.run();
// Now, the file is being read.

const lines = await promise;