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

Document how to make working with abstractions ergonomic

Open aloussase opened this issue 9 months ago • 0 comments

When I want to abstract over the type of Monad (for example when using tagless final) I end up having to write code like this:

export const register = <F extends URIS>(F: UserSymmantics<F> & MonadTask1<F>) => (username: string, password: string) => {
  const flatMap = <A, B>(f: (a: A) => Kind<F, B>) => (ma: Kind<F, A>): Kind<F, B> => F.chain(ma, f)
  return pipe(
    F.fromTask(() => hash(password, 10)),
    flatMap(hashedPassword => F.createUser(username, hashedPassword)),
  )
}

Which is not too bad, but I'd prefer not to write the flatMap function. I'm basing this on the fp to the max example from the repository. Isn't there a more ergonomic way of writing code like this?

Thank you very much.

aloussase avatar May 11 '24 17:05 aloussase