ItemId): F[Result] = for { maybeItem <- ItemRepositoryAlg[F].resolveById(itemId) result <- maybeItem match { case Some(item) => AccountRepositoryAlg[F].resolveById(item.ownerAccountId) .map(_.fold(Result.AccountNotFound, Result.Found(_))) case None => Monad[F].pure(Result.ItemNotFound) } } yield result }
ItemId): F[Result] = for { maybeItem <- ItemRepositoryAlg[F].resolveById(itemId) result <- maybeItem match { case Some(item) => AccountRepositoryAlg[F].resolveById(item.ownerAccountId) .map(_.fold(Result.AccountNotFound, Result.Found(_))) case None => Monad[F].pure(Result.ItemNotFound) } } yield result }
ItemId): F[Result] = for { maybeItem <- ItemRepositoryAlg[F].resolveById(itemId) result <- maybeItem match { case Some(item) => AccountRepositoryAlg[F].resolveById(item.ownerAccountId) .map(_.fold(Result.AccountNotFound, Result.Found(_))) case None => Monad[F].pure(Result.ItemNotFound) } } yield result }
lazy val accountRepository: AccountRepositoryAlg[Future] = new AccountRepositoryOnDB(...) implicit lazy val itemRepository: ItemRepositoryAlg[Future] = new ItemRepositoryOnS3(...) // class GetOwnerAccountOfItem[F[_]: Monad: AccountRepositoryAlg: ItemRepositoryAlg] val getOwnerAccountOfItem = new GetOwnerAccountOfItem[Future] getOwnerAccountOfItem.run(itemId) // e.g. Future(Success(Some(Account(...))))