rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

More utility Js.Promise functions

Open SamWoolerton opened this issue 3 years ago • 1 comments

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)
  }
}

SamWoolerton avatar Jun 12 '21 00:06 SamWoolerton

Check out https://github.com/ryyppy/rescript-promise

em avatar Sep 30 '21 10:09 em

https://github.com/rescript-association/rescript-core would be the right place for any suggestions regarding the standard library.

cknitt avatar May 27 '23 19:05 cknitt