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

Using Maybe for updating only Just values, if any #179

Open
Odeyaloleg opened this issue Aug 17, 2022 · 0 comments
Open

Using Maybe for updating only Just values, if any #179

Odeyaloleg opened this issue Aug 17, 2022 · 0 comments

Comments

@Odeyaloleg
Copy link

Odeyaloleg commented Aug 17, 2022

Hey everyone, I can't find documentation on how to update only Just values having several Maybe's.
Let's say user sent a request asking edit some of his profile fields:

editUser :: MonadSelda m => ID User -> Maybe Text -> Maybe Text -> Maybe Text -> m ()
editUser userId mbNewLogin mbNewPassword mbNewStatus = 
  update_ 
    usersTable
    (\user -> user ! #id .== literal userId)
    (error "What do I do here?")

Perhaps we could replace the error line with something like this:

-- ?:= - is a hypothetical operator for working with Maybe's
(\user -> user `with`
  [ #login ?:= literal <$> mbNewLogin,
    #password ?:= literal <$> mbNewPassword,
    #status ?:= literal <$> mbNewStatus ]
)

Do we have such a functionality in selda?
I wrote my own solution and can post it via pull request or comment, but I am pretty sure I am missing some obvious built-in way of doing this.

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