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

Remove some unnecessary .map #55

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,33 @@ abstract class DatabaseServiceBase[Connection: Tag](connectionSource: Connection

override def transaction[R, E, A](zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false)
(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] =
ZIO.environmentWithZIO[R] { r =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This R can be provided with .provideSomeEnvironment[R](_ ++ ZEnvironment(connection))

runTransaction({ (c: JdbcConnection) =>
connectionFromJdbc(c)
.map(r ++ ZEnvironment(_))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .map was not necessary

.flatMap(zio.provideEnvironment(_))
}, commitOnFailure)
}
runTransaction({ (c: JdbcConnection) =>
connectionFromJdbc(c)
.flatMap { connection => zio.provideSomeEnvironment[R](_.union[Connection](ZEnvironment(connection))) }
// Note: cannot use the simpler `_ ++ ZEnvironment(connection)` instead of the union, because it doesn't compile in 2.12
}, commitOnFailure)

override def transactionOrDieStream[R, E, A](stream: => ZStream[Connection with R, E, A], commitOnFailure: => Boolean = false)
(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZStream[R, E, A] =
ZStream.environmentWithStream[R] { r =>
runTransactionOrDieStream({ (c: JdbcConnection) =>
ZStream.fromZIO(connectionFromJdbc(c))
.map(r ++ ZEnvironment(_))
.flatMap(stream.provideEnvironment(_))
}, commitOnFailure)
}
runTransactionOrDieStream({ (c: JdbcConnection) =>
ZStream
.fromZIO(connectionFromJdbc(c))
.flatMap { connection => stream.provideSomeEnvironment[R](_.union[Connection](ZEnvironment(connection))) }
}, commitOnFailure)

override def autoCommit[R, E, A](zio: => ZIO[Connection with R, E, A])
(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] =
ZIO.environmentWithZIO[R] { r =>
runAutoCommit { (c: JdbcConnection) =>
connectionFromJdbc(c)
.map(r ++ ZEnvironment(_))
.flatMap(zio.provideEnvironment(_))
}
runAutoCommit { (c: JdbcConnection) =>
connectionFromJdbc(c)
.flatMap { connection => zio.provideSomeEnvironment[R](_.union[Connection](ZEnvironment(connection))) }
}

override def autoCommitStream[R, E, A](stream: => ZStream[Connection with R, E, A])
(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZStream[R, Either[DbException, E], A] =
ZStream.environmentWithStream[R] { r =>
runAutoCommitStream { (c: JdbcConnection) =>
ZStream.fromZIO(connectionFromJdbc(c))
.map(r ++ ZEnvironment(_))
.flatMap(stream.provideEnvironment(_))
}
runAutoCommitStream { (c: JdbcConnection) =>
ZStream
.fromZIO(connectionFromJdbc(c))
.flatMap { connection => stream.provideSomeEnvironment[R](_.union[Connection](ZEnvironment(connection))) }
}

}
Expand Down
Loading