Sergei Zubov
07/16/2021, 10:36 AMraulraja
07/16/2021, 10:39 AMraulraja
07/16/2021, 10:45 AMSergei Zubov
07/16/2021, 10:52 AMraulraja
07/16/2021, 11:13 AMinterface Persistence
class LocalPersistence : Persistence
fun Persistence.save(): Unit = TODO()
val singletonPersistence = LocalPersistence()
object TestPersistence : Persistence
fun prototypePersistence(): Persistence = LocalPersistence()
singletonPersistence.save()
TestPersistence.save()
prototypePersistence().save()
Essentially you are stating here that Persistence
is a dependency and you can use save
if you have Persistence
in context.
In this example here you can see composition and another example that uses type bounds to add capabilities to each function in terms of accessing more than one dependency. This can be further simplified with context receivers when they land in Kotlin.
https://gist.github.com/raulraja/97e2d5bf60e9d96680cf1fddcc90ee67raulraja
07/16/2021, 11:26 AMstreetsofboston
07/16/2021, 12:04 PMSergei Zubov
07/16/2021, 12:06 PMSergei Zubov
07/16/2021, 12:09 PMthan_
07/16/2021, 12:45 PMsuspend fun <ENTITY : Any, TABLE> EntityRepository<ENTITY, TABLE, *>.listIntersecting(
dtStart: LocalDateTime,
dtEnd: LocalDateTime,
andOp: Op<Boolean> = Op.TRUE,
): Either<Throwable, List<ENTITY>>
where TABLE : EntityTable<ENTITY>,
TABLE : HasStartTimeColumn,
TABLE : HasEndTimeColumn =
Either.catchAndFlatten {
table.select {
(table.dtStart lessEq dtStart and (table.dtEnd greaterEq dtStart))
...
}
than_
07/16/2021, 12:47 PMraulraja
07/16/2021, 4:08 PM