fp-ts icon indicating copy to clipboard operation
fp-ts copied to clipboard

Reduce suspension in Task to preserve order

Open mikearnaldi opened this issue 2 years ago • 1 comments

closes #1626

Not 100% this is stack safe in any case but it appears to be so

mikearnaldi avatar Dec 24 '21 17:12 mikearnaldi

I am kind of surprised by this but what seems to be affecting is the suspension of map, namely:

export const map: <A, B>(f: (a: A) => B) => (fa: Task<A>) => Task<B> = (f) => (fa) => () => fa().then(f)

this is fine while:

export const map: <A, B>(f: (a: A) => B) => (fa: Task<A>) => Task<B> = (f) => (fa) => () => Promise.resolve().then(() => fa().then(f))

inverts the execution order

mikearnaldi avatar Dec 24 '21 17:12 mikearnaldi