All Projects → functional-promises → Functional Promises

functional-promises / Functional Promises

Licence: mit
Write code like a story w/ a powerful Fluent (function chaining) API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Functional Promises

Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+1495.04%)
Mutual labels:  monad, async, promise
Promise Pool
Map-like, concurrent promise processing
Stars: ✭ 258 (+82.98%)
Mutual labels:  hacktoberfest, async, promises
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (+16.31%)
Mutual labels:  async, promise, composition
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (+2.13%)
Mutual labels:  async, promise, promises
P Map
Map over promises concurrently
Stars: ✭ 639 (+353.19%)
Mutual labels:  async, promise, promises
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+2580.14%)
Mutual labels:  async, promise, promises
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (+38.3%)
Mutual labels:  hacktoberfest, async, promise
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-5.67%)
Mutual labels:  monad, async, promise
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+281.56%)
Mutual labels:  hacktoberfest, monad, composition
Fun Task
Abstraction for managing asynchronous code in JS
Stars: ✭ 363 (+157.45%)
Mutual labels:  monad, async, promise
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-73.05%)
Mutual labels:  async, promise, promises
Promised Pipe
A ramda.pipe-like utility that handles promises internally with zero dependencies
Stars: ✭ 64 (-54.61%)
Mutual labels:  async, promise, composition
Smalltalk
Promise-based Alert, Confirm and Prompt replacement
Stars: ✭ 76 (-46.1%)
Mutual labels:  hacktoberfest, promise
Write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
Stars: ✭ 68 (-51.77%)
Mutual labels:  async, promise
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-43.26%)
Mutual labels:  async, promises
Datakernel
Alternative Java platform, built from the ground up - with its own async I/O core and DI. Ultra high-performance, simple and minimalistic - redefines server-side programming, web-development and highload!
Stars: ✭ 87 (-38.3%)
Mutual labels:  async, promise
Brawlstats
(A)sync python wrapper for the Brawl Stars API
Stars: ✭ 68 (-51.77%)
Mutual labels:  hacktoberfest, async
Vine
Python promises
Stars: ✭ 83 (-41.13%)
Mutual labels:  promise, promises
Taskorama
⚙ A Task/Future data type for JavaScript
Stars: ✭ 90 (-36.17%)
Mutual labels:  async, promise
Crocks
A collection of well known Algebraic Data Types for your utter enjoyment.
Stars: ✭ 1,501 (+964.54%)
Mutual labels:  monad, composition

Functional Promises

Build Status GitHub package version GitHub stars

Updated Documentation: fpromises.io

New Docs

Summary

The Functional Promises library is a Fluent API supporting a specific Function Chaining technique (using composition).

Note: FP doesn't replace or extend Promises. It uses them.

There are many names for this general pattern. Including Collection Pipeline and Promise Chain. The emphasis here is a seamless async/sync Developer Experience.

I call this pattern a Functional River - your data is the water, and your functions describe its path or riverbed.

Advantages

  • Only 400 Lines of Source & 3Kb compressed
  • Easily handle Sync, Async, Events, Promises, and Callbacks.
  • Familiar methods, including Array.prototype.map, [].filter(), [].find(), [].some(), etc.
  • Create Monads in JavaScript (so far as they contain side-effects to a sequence of instructions).
  • Point-free code is easily achieved (no temp variables).
  • Higher code test coverage w/ less repetitive code in tests.
  • Use the best features from multiple programming styles: a little imperative, plenty functional, a pinch of OOP, yet still resembling declarative methods!!!

Library Comparison

Total Lines of Code (LoC) calculated using cloc CLI utility.

LoC #'s included because a smaller surface === fewer places bugs can hide.

Library Main deal Files Lines of Code .min.js kB
Functional Promise v1.8.1 Sync & Async Chains 8 375 12 Kb (3Kb compressed)
Bluebird v3.5.1 Promises Replacement 38 5,188 80 Kb
RxJS v5.5.6 Observables Chaining 458 12,266 150 Kb
IxJS v2.3.4 [Async]Iterable Chaining 521 12,366 145 Kb

Admittedly IxJS/RxJS have a far larger API than FP also some behavior in RxJS/IxJS may never be added. Currently however there is a lot of overlap with FP (plus more planned).

The table above show FP is roughly 1/30th the LOC (lines of code) in R/IxJs. FP's bundle size is about 10% the size of either RxJS/IxJS.

BluebirdJS and FP have roughly the same number of API methods, yet Bluebird has a fair bit more code.

To be clear: Bluebird and RxJS/IxJS are amazing. Their interface/designs has been very influential on FP.

Note: R/IxJS's hyper-modular design also allows for bundles to be lots smaller (though using quite different syntax, either .pipe(...) or ix/iterable/ix/add/...).

Installation

npm install functional-promises

Getting Started

Use one of the following:

const FP = require('functional-promises')
// or:
import FP from 'functional-promises'

Quick Examples

Using .map()

FP.resolve([1, 2, 3, 4, 5])
  .map(x => x * 2)
  .map(x => x * 2)
  .then(results => {
    // results === [4, 8, 12, 16, 20]
  })

Handling Events

Create function chains to handle the case where promises don't fit very naturally.

For example streams & event handlers must (usually) support multiple calls over time.

Here's how FP.chain() and FP.chainEnd()/FP.listen(obj, event) help you handle this like a pro:

const button = document.getElementById('submitBtn')
FP.chain() // start a chain
  .then(({target}) => { // destructure 'target' from the `event`
    target.textContent = 'Clicked!'
  })
  .listen(button, 'click') // end the repeatable chain, started at `.chain()`

API Outline

Development

git clone [email protected]:functional-promises/functional-promises.git
cd functional-promises
npm install
npm test

Thanks to several influencial projects: RxJS, IxJS, Bluebird, asynquence, FantasyLand, Gulp, HighlandJS, et al.

Special thanks to Kyle Simpson, Eric Elliot, and Sarah Drasner for their work for the OSS community, as well as their advice & encouragement.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].