ryyppy / rescript-promise

Proposal for a proper Js.Promise binding
128 stars 14 forks source link

Chaining a side effect function? #18

Open jaredramirez opened 2 years ago

jaredramirez commented 2 years ago

Hey there, thanks for the great bindings!

Have you thought about adding a function like

let tap: (Promise.t<'val>, 'val => unit)

The purpose of such a function would be to chain a side effect based on the value of a promise. For example, setting some React state if a promise is successful or logging in between thens

Currently, this can be achieved with

let tap = (p, f) = Promise.thenResolve(p, v => {
    f(v)
    v
  })
ryyppy commented 2 years ago

This lib tries to be runtime free as much as possible and also tries to stick to JS' promise apis. Maybe something like this could end up in a dedicated utility module within Belt at some point.