Skip to content

Instantly share code, notes, and snippets.

@fomkin
Created December 1, 2020 12:29
Show Gist options
  • Save fomkin/35ffbd05aeb0a71baa6e0f13ee58cb5f to your computer and use it in GitHub Desktop.
Save fomkin/35ffbd05aeb0a71baa6e0f13ee58cb5f to your computer and use it in GitHub Desktop.
trait MyService[F[_], S[_]] {
def getItem(id: Long): F[Item]
def getItemsByGroup(groupId): F[S[Item]]
}
class MyServiceImpl[F[_], S[_]](xa: Transactor[F]) extends MyService {
def getItemsByGroup(groupId): S[Item] = {
val stream = sql"select * from items where group = $groupId"
.query[Item]
.stream
.transact(xa)
// Convers fs2.Stream[F, Item] to S[_] in both of them have `tofu.streams` instances.
StreamAdapter(stream)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment