Skip to content

introduce ImplicitOptArg #655

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

Closed
wants to merge 3 commits into from
Closed

introduce ImplicitOptArg #655

wants to merge 3 commits into from

Conversation

halotukozak
Copy link
Member

@halotukozak halotukozak commented Dec 6, 2024

ImplicitOptArg is like OptArg, but also accept implicit parameters (useful for DI or context parameters)

Example usage:

  class ClientSession

  val NoSession = ImplicitOptArg.Empty[ClientSession]

  class TransactionManager {
    def execute(transaction: ClientSession => Unit): Unit = ???
  }

  val transactionManager = new TransactionManager

  def doSomething(implicit session: ImplicitOptArg[ClientSession]): Unit = ???

  doSomething(using NoSession) // explicitly passing NoSession

  transactionManager.execute { implicit session =>
    doSomething // implicit session is passed
  }

@halotukozak
Copy link
Member Author

@ddworak can we either proceed or close this PR?

@ddworak
Copy link
Member

ddworak commented Jun 23, 2025

Thank you for proposing this idea. I don't think we should encourage implicit parameters with default values, especially when combined with optionality. OptArgs are often used in contexts where explicitness is highly desired (e.g. configuration, application bootstrap).

@ddworak ddworak closed this Jun 23, 2025
@halotukozak
Copy link
Member Author

halotukozak commented Jun 23, 2025

Thank you for proposing this idea. I don't think we should encourage implicit parameters with default values, especially when combined with optionality. OptArgs are often used in contexts where explicitness is highly desired (e.g. configuration, application bootstrap).

we do not encourage implicit parameters with default values. The default ones still must be passed explicitly (how it's already done internally with MaybeClientSession in DHCP and CAE with UserContext).
But I see, this mechanism could be abused

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