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

added toOption member to Flag for use in for comprehensions #10

Closed
wants to merge 1 commit into from

Conversation

klaeufer
Copy link

Signed-off-by: Konstantin Läufer klaeufer@gmail.com

Example:

      for {
        true <- OptionT.fromOption[Try](options.createDatabase.toOption)
        () <- withDAO { dao => dao.createDatabase() }
      } yield printMessageFormat("created")

In context:

https://github.com/LoyolaChicagoCode/worddb-slick-scala/blob/main/src/main/scala/Main.scala#L62-L65

Signed-off-by: Konstantin Läufer <klaeufer@gmail.com>
@lihaoyi
Copy link
Member

lihaoyi commented May 23, 2021

This is kind of odd; Flag is basically a glorified Boolean. Converting it into an Option[true] seems like a pretty obscure use case that I don't think needs to be part of the library (though feel free to implement it in your own code!)

@klaeufer
Copy link
Author

Good point: one could make a similar argument for Boolean to support toOption. The only use case I can think of is for starting a for-comprehension for Option like in my example because if it's further down in the for-comprehension, one can simply use a filter. So I agree that this would be a bit obscure but not all that uncommon when the first step of the for-comprehension is to check whether a particular flag is set.

@klaeufer klaeufer closed this May 24, 2021
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

Successfully merging this pull request may close these issues.

2 participants