-
Notifications
You must be signed in to change notification settings - Fork 49
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
DataSourceCache parameterised to F[_] #160
Conversation
Codecov Report
@@ Coverage Diff @@
## master #160 +/- ##
=========================================
+ Coverage 91.12% 95.2% +4.08%
=========================================
Files 5 5
Lines 169 167 -2
Branches 5 4 -1
=========================================
+ Hits 154 159 +5
+ Misses 15 8 -7
Continue to review full report at Codecov.
|
shared/src/main/scala/cache.scala
Outdated
}) | ||
trait DataSourceCache[F[_]] { | ||
def lookup[I, A](i: I, ds: DataSource[I, A])( | ||
implicit C: ConcurrentEffect[F], P: Par[F] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we didn't put these constraints on the methods anymore.
Now that we have parametrized DataSourceCache
on F
, the implementation could specify the constraints.
For example for InMemoryCache
we would only need Applicative
(Monad
for foldLeftM
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'm going to try to remove these constraints from the trait.
@juanpedromoreno @peterneyens Updated with Peter's feedback, let me know if I can go ahead and merge this. |
)( | ||
implicit | ||
P: Par[F], | ||
C: ConcurrentEffect[F], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be this replaced by Monad
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid is not. The effect type F[_]
of the DataSource
instances requires a ConcurrentEffect[F]
and Par[F]
. For running F
we need ContextShift[F]
and Timer[F]
so these are the less restrictive implicits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need Sync
for Ref.of
and the DataSource
methods still require ConcurrentEffect
at the moment.
So performRun
and co need ConcurrentEffect
as well.
docs/src/main/tut/docs.md
Outdated
@@ -526,7 +526,7 @@ The default cache is implemented as an immutable in-memory map, but users are fr | |||
There is no need for the cache to be mutable since fetch executions run in an interpreter that uses the state monad. Note that the `update` method in the `DataSourceCache` trait yields a new, updated cache. | |||
|
|||
```scala | |||
trait DataSourceCache { | |||
trait DataSourceCache[F[_]] { | |||
def insert[F[_] : ConcurrentEffect, I, A](i: I, ds: DataSource[I, A], v: A): DataSourceIdentity, v: A): F[DataSourceCache] | |||
def lookup[F[_] : ConcurrentEffect, I, A](i: I, ds: DataSource[I, A]): F[Option[A]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are no longer correct, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right!
)( | ||
implicit | ||
P: Par[F], | ||
C: ConcurrentEffect[F], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need Sync
for Ref.of
and the DataSource
methods still require ConcurrentEffect
at the moment.
So performRun
and co need ConcurrentEffect
as well.
@peterneyens @juanpedromoreno i opened #163 to discuss about the implicits required when implementing data sources, let me know your thoughts in there. Can I merge this ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement of DataSourceCache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 👌
DataSourceCache parameterised to F[_]
I changed
DataSourceCache
so we can parameterise it toF[_] : Monad
. It also helps for implementing custom caches that make use of io for serialization/deserialization.