SkillAgentSearch skills...

Fluture

🦋 Fantasy Land compliant (monadic) alternative to Promises

Install / Use

/learn @fluture-js/Fluture

README

Fluture

Build Status Code Coverage Dependency Status NPM Package Gitter Chat

Fluture offers a control structure similar to Promises, Tasks, Deferreds, and what-have-you. Let's call them Futures.

Much like Promises, Futures represent the value arising from the success or failure of an asynchronous operation (I/O). Though unlike Promises, Futures are lazy and adhere to the monadic interface.

Some of the features provided by Fluture include:

For more information:

  • API documentation
  • [Article: Introduction to Fluture - A Functional Alternative to Promises][10]
  • [Wiki: Compare Futures to Promises][wiki:promises]
  • [Wiki: Compare Fluture to similar libraries][wiki:similar]
  • [Video: Monad a Day - Futures by @DrBoolean][5]

Installation

With NPM

$ npm install --save fluture

Bundled from a CDN

To load Fluture directly into a browser, a code pen, or [Deno][], use one of the following downloads from the JSDelivr content delivery network. These are single files that come with all of Fluture's dependencies pre-bundled.

  • Fluture Script: A JavaScript file that adds Fluture to the global scope. Ideal for older browsers and code pens.
  • Fluture Script Minified: The same as above, but minified.
  • Fluture Module: An EcmaScript module with named exports. Ideal for Deno or modern browsers.
  • Fluture Module Minified: A minified EcmaScript module without TypeScript typings. Not recommended for Deno.

Usage

EcmaScript Module

Fluture is written as modular JavaScript.

  • On Node 12 and up, Fluture can be loaded directly with import 'fluture'.
  • On some older (minor) Node versions, you may need to import from 'fluture/index.js' instead, and/or pass --experimental-modules to node.
  • On Node versions below 12, the [esm loader][esm] can be used. Alternatively, there is a CommonJS Module available.
  • Modern browsers can run Fluture directly. If you'd like to try this out, I recommend installing Fluture with [Pika][] or [Snowpack][]. You can also try the bundled module to avoid a package manager.
  • For older browsers, use a bundler such as [Rollup][] or WebPack. Besides the module system, Fluture uses purely ES5-compatible syntax, so the source does not have to be transpiled after bundling. Alternatively, there is a CommonJS Module available.
import {readFile} from 'fs'
import {node, encase, chain, map, fork} from 'fluture'

const getPackageName = file => (
  node (done => { readFile (file, 'utf8', done) })
  .pipe (chain (encase (JSON.parse)))
  .pipe (map (x => x.name))
)

getPackageName ('package.json')
.pipe (fork (console.error) (console.log))

CommonJS Module

Although the Fluture source uses the EcmaScript module system, the main file points to a CommonJS version of Fluture.

On older environments one or more of the following functions may need to be polyfilled: [Object.create][JS:Object.create], [Object.assign][JS:Object.assign] and [Array.isArray][JS:Array.isArray].

const fs = require ('fs')
const Future = require ('fluture')

const getPackageName = function (file) {
  return Future.node (function (done) { fs.readFile (file, 'utf8', done) })
  .pipe (Future.chain (Future.encase (JSON.parse)))
  .pipe (Future.map (function (x) { return x.name }))
}

getPackageName ('package.json')
.pipe (Future.fork (console.error) (console.log))

Documentation

Table of contents

<details open><summary>General</summary> </details> <details><summary>Creating new Futures</summary> </details> <details><summary>Converting between Nodeback APIs and Futures</summary> </details> <details><summary>Converting between Promises and Futures</summary> </details> <details><summary>Transforming and combining Futures</summary> </details> <details><summary>Consuming/forking Futures</summary> </details> <details><summary>Concurrency related utilities and data structures</summary> </details> <details><summary>Resource management</summary> </details> <details><summary>Other utilities</summary> </details>

Butterfly

The name "Fluture" is a conjunction of "FL" (the acronym to [Fantasy Land][FL]) and "future". Fluture means butterfly in Romanian: A creature one might expect to see in Fantasy Land.

Credit goes to Erik Fuente for styling the logo, and [WEAREREASONABLEPEOPLE][9] for sponsoring the project.

Interoperability

[<img src="https://raw.github.com/fantasyland/fantasy-land/m

View on GitHub
GitHub Stars2.5k
CategoryDevelopment
Updated9d ago
Forks83

Languages

JavaScript

Security Score

100/100

Audited on Mar 18, 2026

No findings