Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to make working with abstractions ergonomic #1936

Open
aloussase opened this issue May 11, 2024 · 0 comments
Open

Document how to make working with abstractions ergonomic #1936

aloussase opened this issue May 11, 2024 · 0 comments

Comments

@aloussase
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant