-
Notifications
You must be signed in to change notification settings - Fork 10
Future=IO[Void,(Time,A) #15
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 1,21 @@ | ||
package scalaz.reactive | ||
import scalaz.Monoid | ||
import scalaz.zio.{IO, RTS} | ||
import scalaz.zio.{ IO, RTS } | ||
|
||
case class Event[A](value: Future[Reactive[A]]) extends RTS { self => | ||
case class Event[A](value: Future[Reactive[A]]) extends RTS { self => | ||
|
||
def merge(v: Event[A]): Event[A] = { // if Event[ A]: covariant type A occurs in contravariant position | ||
def merge( | ||
v: Event[A] | ||
): Event[A] = { // if Event[ A]: covariant type A occurs in contravariant position | ||
|
||
val winner: IO[Nothing, Either[(Time, Reactive[A]), (Time, Reactive[A])]] = | ||
self.value.force.map(Left(_)).race(v.value.force.map(Right(_))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to put them inside an Either, the resulting IO will have the winner, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True - at one moment I had the idea I needed the loser too, but that is not the case. |
||
|
||
val io: IO[Nothing, Future[Reactive[A]]] = winner.map(_ match { | ||
case Left((t, r)) => | ||
Future((t, Reactive(r.head, r.tail))) | ||
Future((t, Reactive(r.head, r.tail))) | ||
case Right((t, r)) => | ||
Future((t, Reactive(r.head, r.tail))) | ||
Future((t, Reactive(r.head, r.tail))) | ||
}) | ||
|
||
Event(unsafeRun(io)) // That is not good | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it is not good, we should NEVER use the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, once we are in IO, we have to stay in the IO, so I can't think of another way to do this at the moment. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 1,17 @@ | ||
package scalaz.reactive | ||
|
||
import scalaz.Scalaz._ | ||
import scalaz.reactive.Time.{NegInf, PosInf} | ||
import scalaz.reactive.Time.{ NegInf, PosInf } | ||
import scalaz.zio.IO | ||
import scalaz.{Applicative, Functor, Monad, Monoid} | ||
import scalaz.{ Applicative, Functor, Monad, Monoid } | ||
|
||
object Types { | ||
type Infallible[A] = IO[Nothing, A] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be |
||
} | ||
|
||
case class Future[ A](force: IO[Nothing, (Time, A)]) { | ||
|
||
def [AA >: A](other: Future[AA]): Future[AA] = | ||
def [AA >: A](other: Future[AA]): Future[AA] = | ||
Future(force.flatMap { | ||
case (t1, a1) => | ||
other.force.map { | ||
|
@@ -29,9 29,8 @@ case class Future[ A](force: IO[Nothing, (Time, A)]) { | |
.map { case (t2, f) => (t2.max(t), f(a)) } // There should be IO.ap, is there? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we could use IO ap instead of flatMap, I am not sure what are the difference in the semantics of the IO ap and flatMap, they are the same if ap is defined in terms of flatMap |
||
}) | ||
|
||
def flatMap[B](f: A => Future[B]): Future[B] = { | ||
def flatMap[B](f: A => Future[B]): Future[B] = | ||
Future(force.flatMap { case (_, a) => f(a).force }) // FIXME - what to do with the times | ||
} | ||
} | ||
|
||
object Future extends FutureInstances0 { | ||
|
@@ -85,8 84,7 @@ trait FutureInstances2 { | |
override def point[A](a: => A): Future[A] = | ||
Future.point(a) | ||
|
||
override def bind[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = { | ||
override def bind[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = | ||
Future(fa.force.flatMap { case (_, a) => f(a).force }) | ||
} | ||
} | ||
} |
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.
Let's not remove variance, the way it is done is by providing events of a supertype of A, so the type signature of merge must be:
def merge[AA >: A](v: Event[AA]): Event[AA]
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.
fixed, thanks