All Projects → digitake → bs-promise-monad

digitake / bs-promise-monad

Licence: MIT License
Monadic syntax to work with promise in ReasonML

Programming Languages

reason
219 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to bs-promise-monad

queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
Stars: ✭ 56 (+47.37%)
Mutual labels:  promise
naboris
Simple, fast, minimalist http server for OCaml/ReasonML
Stars: ✭ 71 (+86.84%)
Mutual labels:  reasonml
futura
Asynchronous Swift made easy. The project was made by Miquido. https://www.miquido.com/
Stars: ✭ 34 (-10.53%)
Mutual labels:  promise
reason-nodejs
Node bindings for Reason and Bucklescript
Stars: ✭ 105 (+176.32%)
Mutual labels:  reasonml
bitmex-orderbook
The fastest order book implementation for the BitMEX WebSocket API.
Stars: ✭ 73 (+92.11%)
Mutual labels:  promise
rescript-urql
ReScript bindings for Formidable's Universal React Query Library, urql.
Stars: ✭ 230 (+505.26%)
Mutual labels:  reasonml
lifx-http-api
💡 Thin wrapper around the Lifx HTTP API (http://api.developer.lifx.com/)
Stars: ✭ 17 (-55.26%)
Mutual labels:  promise
credt
CRDT-like data structures for building distributed, offline-first applications
Stars: ✭ 32 (-15.79%)
Mutual labels:  reasonml
bs-getenv
ReasonML/BuckleScript PPX for embedding env variables
Stars: ✭ 25 (-34.21%)
Mutual labels:  reasonml
doasync
Promisify functions and objects immutably
Stars: ✭ 27 (-28.95%)
Mutual labels:  promise
chomex
Chrome Extension Messaging Routing Kit / Promisify Chrome Messaging / LocalStorage Object Mapper
Stars: ✭ 41 (+7.89%)
Mutual labels:  promise
awesome-ppx-reasonml
curated list of reasonml PPX rewriter
Stars: ✭ 28 (-26.32%)
Mutual labels:  reasonml
rescript-game-of-life
Game of Life in ReasonML with ReasonReact in 2020
Stars: ✭ 36 (-5.26%)
Mutual labels:  reasonml
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-44.74%)
Mutual labels:  promise
REInfer
Runtime Extended Inference for json data.
Stars: ✭ 23 (-39.47%)
Mutual labels:  reasonml
purescript-promises
An alternative effect monad for PureScript.
Stars: ✭ 23 (-39.47%)
Mutual labels:  promise
android-promise
A Javascript style Promise library for Android JVM
Stars: ✭ 23 (-39.47%)
Mutual labels:  promise
rescript-react-compat
An alternative upgrade path for ReasonReact
Stars: ✭ 17 (-55.26%)
Mutual labels:  reasonml
executive
🕴Elegant command execution for Node.
Stars: ✭ 37 (-2.63%)
Mutual labels:  promise
bs-react-is-visible
A small library that lets you know whether a component is visible on screen or not.
Stars: ✭ 15 (-60.53%)
Mutual labels:  reasonml

bs-promise-monad

Monadic syntax to work with promise in ReasonML

This project is a minimal syntax extension that help you to be more happy, and keep every promise in a way.


Package Quality

status

This module is simple and self-completed. It means that you can use it with confidence that it won't bring any breaking changes in a subsequent update.

installation

npm install bs-promise-monad --save

and add

bs-promise-monad into bsconfig.json.

Usage

simply

open PromiseMonad;

and enjoy life.

Example

let mySweetenPromise = return(2);

mySweetenPromise
>>= (value => {
    Js.log(value);
    return(value + 2);
  })
>>= (value => {
    Js.log(value);
    return(value + 3);
  })
>>| (err => {
    Js.log2("Failure!!", err);
    return(-2);
  });

/* With auto binding */
mySweetenPromise
>>- (value => {Js.log2("from first promise:",value); value+2})
>>- (value => {Js.log2("from second promise:", value); value+3})
>>- (err => {Js.log2("Handled error", err); err})

Reject the promise

exception Sorry;

error(Sorry)
>>= (x => Js.log("do it " ++ x) |> return)
>>| (err => return(Js.log2("I handled this", err)));
exception Sorry;
let breakPromise = return("I'm trying...");

breakPromise 
>>= ( x => Js.log("Program: " ++ x) |> return )
>>= ( y => error(Sorry) )   /* Reject here */
>>= ( z => Js.log("this is skipped")|>return)
>>| ( err => Js.log2("Handled error!!", err)|>return); /* Error handling here */

breakPromise 
>>- ( x => Js.log("Program: " ++ x))
>>- ( y => error(Sorry) )
>>- ( z => Js.log("this will be skipped"))
>>/ ( err => Js.log2("Handled error!! without explicit return", err));
let sequenceStart = return(7);

breakPromise >>* [
  (x => x+2),
  (x => x*3),
  (x => x+4)
]

Change

  • v0.4.3 : Remove unused dependency
  • v0.4.1 : Add >>* operator
  • v0.4.1 : Update bs-platfrom to 7.3.1
  • v0.4.0 : Update bs-platform, bs-webapi. Add auto-catch(>>/) from @rolandpeelen . Many thanks!!
  • v0.3.3 : fix module dependencies
  • v0.3.0 : merge in auto-return(>>-) from @baldurh . Thanks!!
  • v0.2.9 : fix type signature.
  • v0.2.6 : update example on error handling
  • v0.2.5 : add error handling (>>|)
  • v0.2.0 : add Promise.reject by error
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].