Skip to content

DataSourceCache parameterised to F[_] - #160

Merged
purrgrammer merged 11 commits into
masterfrom
parameterised-cache
Sep 25, 2018
Merged

DataSourceCache parameterised to F[_]#160
purrgrammer merged 11 commits into
masterfrom
parameterised-cache

Conversation

@purrgrammer

@purrgrammer purrgrammer commented Sep 20, 2018

Copy link
Copy Markdown
Contributor

I changed DataSourceCache so we can parameterise it to F[_] : Monad. It also helps for implementing custom caches that make use of io for serialization/deserialization.

@codecov

codecov Bot commented Sep 20, 2018

Copy link
Copy Markdown

Codecov Report

Merging #160 into master will increase coverage by 4.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
shared/src/main/scala/fetch.scala 95.42% <100%> (+3.42%) ⬆️
shared/src/main/scala/cache.scala 100% <100%> (+20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27ea529...3c19563. Read the comment docs.

@purrgrammer purrgrammer changed the title DataSourceCache as abstract class instead of trait DataSourceCache parameterised to F[_] Sep 20, 2018
Comment thread 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]

Copy link
Copy Markdown
Contributor

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).

@purrgrammer purrgrammer Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

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.

@purrgrammer

Copy link
Copy Markdown
Contributor Author

@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],

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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.

Comment thread docs/src/main/tut/docs.md Outdated
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]]

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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],

Copy link
Copy Markdown
Contributor

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.

@purrgrammer

Copy link
Copy Markdown
Contributor Author

@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 :shipit: ?

@peterneyens peterneyens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice improvement of DataSourceCache

@juanpedromoreno juanpedromoreno left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work 👌

@purrgrammer
purrgrammer merged commit e7c7e1c into master Sep 25, 2018
bijancn pushed a commit to bijancn/fetch that referenced this pull request Sep 19, 2019
@fedefernandez
fedefernandez deleted the parameterised-cache branch October 16, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants