Skip to content

Add Fetch#runAll - #194

Merged
purrgrammer merged 2 commits into
masterfrom
run-all
May 20, 2019
Merged

Add Fetch#runAll#194
purrgrammer merged 2 commits into
masterfrom
run-all

Conversation

@purrgrammer

Copy link
Copy Markdown
Contributor

No description provided.

*/
def runAll[F[_]]: FetchRunnerAll[F] = new FetchRunnerAll[F]

private[fetch] class FetchRunnerAll[F[_]](private val dummy: Boolean = true) extends AnyVal {

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.

What's the purpose of dummy?

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.

It's just a dummy attribute to be able to define a class with the apply method diferent arities.

@diesalbla diesalbla May 15, 2019

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.

What would be the problem of using just two functions?

def runAll[F[_]: Concurrent: Timer, A](fa: Fetch[F, A])
    : F[(Log, DataCache[F], A)] = 
  runAll(fa, InMemoryCache.empty[F])

def runAll[F[_]: Concurrent: Timer, A](fa: Fetch[F, A], cache: DataCache[F])
  : F[(Log, DataCache[F], A)] = /**/ 

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.

We use this technique to be able to partially apply the type parameters in Fetch.run* methods, so you can do Fetch.run[IO](f) and omit the second type parameter. It doesn't work with an overloaded method.

@diesalbla diesalbla May 15, 2019

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.

What about using a syntax extension on the Fetch[F, A] element?

implicit class FetchRunOps[F[_], A](val fa: Fetch[F, A]){
  def runAll()(implicit /****/) : F[(Log, DataCache[F], A)] = /***/

  def runAll(cache: DataCache[F])(implicit /***/) : F[(Log, DataCache[F], A)] = /***/
}

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.

Still haven't added syntax for run* methods, it's actually a bit tricky. Opened #195 to address it.

@purrgrammer
purrgrammer merged commit 88b14dd into master May 20, 2019
@purrgrammer
purrgrammer deleted the run-all branch May 20, 2019 11:09
bijancn pushed a commit to bijancn/fetch that referenced this pull request Sep 19, 2019
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