Bob Glamm
07/30/2019, 2:18 AMfun <F> IO<F>.runner(connection: Connection): JDBCOps<F> =
object: JDBCOps<F>, Fx<F> by this, Bracket<F, Throwable> by this {
doesn't work because Fx<F> is not Bracketsimon.vergauwen
07/30/2019, 12:06 PMobject: JDBCOps<F>, Concurrent<F> by this {
This is what you want. Don’t bother with Fx they’re being removed in 0.10 anyway. And you can currently also use it from Concurrent, in the next release Fx is merged into Concurrent.simon.vergauwen
07/30/2019, 12:07 PMConcurrent also is Bracket inherited through Async.simon.vergauwen
07/30/2019, 12:08 PMfun <F> runner(connection: Connection, CF: Concurrent<F>): JDBCOps<F> =
object: JDBCOps<F>, Concurrent<F> by CF {
override val connection = connection
}simon.vergauwen
07/30/2019, 12:09 PMFx for, or even which one since the package is missing. You can still drop the Concurrent constraint to Async or just Bracket depending on what you use Fx for currently.Bob Glamm
07/30/2019, 12:37 PMFx for fx. The following type-checks but I'm not sure if the usage of fx.monad below is intended:
interface JDBCOps<F>: Bracket<F, Throwable> {
val connection: Connection
fun <A> withStatement(query: String, rsMapper: (ResultSet) -> Kind<F, A>): Kind<F, A> =
fx.monad { connection.createStatement() }.bracket(
{ stmt -> fx.monad { stmt.close() } },Bob Glamm
07/30/2019, 12:37 PMsimon.vergauwen
07/30/2019, 12:38 PMFx that it was import based. Which people found very confusing to use, the reason we did so was so we could enable syntax through the receiver type of fx { }.simon.vergauwen
07/30/2019, 12:39 PMfx into the typeclasses themselves but you have to specify which syntax you want enabled. There is monad, monadFilter, concurrent, async, .. depending on which typeclass you’re using. Besides that there is no difference.simon.vergauwen
07/30/2019, 12:40 PMfx.monad { connection.createStatement() } as effect { connection.createStatement() } or at least that’s what it looks like to me.Bob Glamm
07/30/2019, 12:41 PMfx. For new code is it just better to use something like effect?simon.vergauwen
07/30/2019, 12:42 PMeffect is to wrap impure code (including suspend). fx is typically used for bind() or !.Bob Glamm
07/30/2019, 12:43 PMfx.BLAH syntax is simply selecting some level of monad to use - e.g. fx.async says I need a monad instance that at least supports the async effect?simon.vergauwen
07/30/2019, 12:46 PMMonad has a property val fx, but depending on which typeclass you’ll be able to enable more or less syntax.
For example.
fun <F> exampleOne(AS: Async<F>): Kind<F, Unit> = AS.fx.async { // receiver of type `AsyncSyntax<F>
continueOn(CommonPool)
just(Unit).bind()
}
fun <F> exampleOne(AS: Async<F>): Kind<F, Unit> = AS.fx.monad { // receiver of type `MonadSyntax<F>
// continueOn(CommonPool) <-- not available for MonadSyntax
just(Unit).bind()
}simon.vergauwen
07/30/2019, 12:47 PMMonad cannot enable fx.asyncBob Glamm
07/30/2019, 12:49 PMBob Glamm
07/30/2019, 12:50 PMfun <F> runner(connection: Connection, BF: Bracket<F, Throwable>): JDBCOps<F> =
object: JDBCOps<F>, Bracket<F, Throwable> by BF {
...
fun foo(c: Connection) {
runner(c, IO.bracket())
}
but removing the BF parameter and replacing by BF with by IO.bracket() does not