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

Conveniences that could be added to DBIO #2878

Open
nafg opened this issue Dec 22, 2023 · 3 comments
Open

Conveniences that could be added to DBIO #2878

nafg opened this issue Dec 22, 2023 · 3 comments

Comments

@nafg
Copy link
Member

nafg commented Dec 22, 2023

  • DBIO.unit: DBIO[Unit]
  • DBIO.traverse[A, B, C[x] <: Iterable[x]](C[A])(A => DBIO[B]): DBIO[C[B]]
  • DBIO.defer[A](=>A): DBIO[A]
  • [A] DBIO[A]#void: DBIO[Unit] (or another name)
@iRevive
Copy link
Contributor

iRevive commented Mar 9, 2024

  • [A] DBIO[A]#as(A): DBIO[A] could be useful to: a shortcut for .map(_ => a).

mergify bot added a commit that referenced this issue Apr 14, 2024
A few convenience methods from the
#2878.
@iRevive
Copy link
Contributor

iRevive commented Apr 15, 2024

DBIO.defer[A](=>A): DBIO[A]

cats-effect IO has these meanings for delay / defer:

def delay[A](thunk: => A): IO[A] = ???
def defer[A](thunk: => IO[A]): IO[A] = delay(thunk).flatten

ZIO has defer only for the Config:

def defer[A](config: => Config[A]): Config[A]

Following this logic, the signature of the defer should be:

object DBIO {
  def defer[A](a: => DBIO[A]): DBIO[A]
}

In terms of the side-effect suspension, ZIO has:

def attempt[A](code: => A)(implicit trace: Trace): Task[A]
def succeed[A](a: => A)(implicit trace: Trace): ZIO[Any, Nothing, A]

Do you think we should consider other names for the [A](=>A): DBIO[A] signature?

  • apply
  • delay
  • attempt

Since the DBIO API is similar to Future, DBIO.apply may fit. But I don't have a strong opinion, to be honest.

@nafg
Copy link
Member Author

nafg commented Apr 17, 2024

Not sure. Another options is .successfulLazy or something in that direction.

delay and attempt are good. Not sure about apply. In the case of Future, just opening up a block and marking it asynchronous is a basic way to use Future. Constructing a lazy DBIO is much more arcane, so I don't know if it deserves apply.

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

2 participants