-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
217 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
modules/core/src/main/scala/sangria/execution/EffectScheme.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sangria.execution | ||
|
||
import scala.collection.BuildFrom | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
trait EffectScheme { | ||
type F[_] | ||
def map[A, B](eff: F[A])(f: A => B): F[B] | ||
def flatMap[A, B](eff: F[A])(f: A => F[B]): F[B] | ||
def success[A](a: A): F[A] | ||
def sequence[A, CC[X] <: IterableOnce[X]](in: CC[F[A]])(implicit | ||
bf: BuildFrom[CC[F[A]], A, CC[A]]): F[CC[A]] | ||
def fromFuture[A](f: Future[A]): F[A] | ||
def toFuture[A](f: F[A]): Future[A] | ||
} | ||
|
||
class FutureEffectScheme(implicit ec: ExecutionContext) extends EffectScheme { | ||
override type F[A] = Future[A] | ||
|
||
override def map[A, B](eff: Future[A])(f: A => B): Future[B] = eff.map(f) | ||
override def flatMap[A, B](eff: Future[A])(f: A => Future[B]): Future[B] = eff.flatMap(f) | ||
override def success[A](a: A): Future[A] = Future.successful(a) | ||
def sequence[A, CC[X] <: IterableOnce[X]](in: CC[Future[A]])(implicit | ||
bf: BuildFrom[CC[Future[A]], A, CC[A]]): Future[CC[A]] = | ||
Future.sequence(in) | ||
override def fromFuture[A](f: Future[A]): Future[A] = f | ||
override def toFuture[A](f: Future[A]): Future[A] = f | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.