rescript-compiler
rescript-compiler copied to clipboard
More utility Js.Promise functions
I put together these utility functions for a project I'm working on and thought they'd likely be useful to others. Is there an official way of giving suggestions to improve the standard libraries?
The initial impetus for this was the lack of type-checking for .then_
because it hasn't been moved to data-first/pipe-first style, but the other utility functions are helpful too.
module Promise = {
open Js
let map = (promise, fn) => {
Promise.then_(val => val->fn->Promise.resolve, promise)
}
let flatMap = (promise, fn) => {
Promise.then_(fn, promise)
}
let trace = promise => {
Promise.then_(val => {
Js.log(val)
Promise.resolve(val)
}, promise)
}
let tap = (promise, fn) => {
Promise.then_(val => {
fn(val)
Promise.resolve(val)
}, promise)
}
}
Check out https://github.com/ryyppy/rescript-promise
https://github.com/rescript-association/rescript-core would be the right place for any suggestions regarding the standard library.