This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
! core: Refactor concurrency support
* Tweak#apply, Snail#apply and Transformer#apply now return UI actions. * Removed InPlaceFuture and (partly) incorporated the in-place optimizations into UiFuture. * Effector#foreach now takes a UI action. * Removed Ui#flatRun, added Ui#withResult and Ui#withResultAsync. * Taking advantage of all of the above, simplified Tweaking and Snailing.
- Loading branch information
Showing
6 changed files
with
113 additions
and
109 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
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
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
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 |
---|---|---|
@@ -1,30 +1,31 @@ | ||
package macroid.util | ||
|
||
import macroid.Ui | ||
import macroid.UiThreading.UiFuture | ||
|
||
import scala.language.higherKinds | ||
import scala.concurrent.{ Future, ExecutionContext } | ||
import scala.util.Try | ||
|
||
trait Effector[-F[_]] { | ||
def foreach[A](fa: F[A])(f: A ⇒ Any): Unit | ||
def foreach[A](fa: F[A])(f: A ⇒ Ui[Any]): Unit | ||
} | ||
|
||
object Effector { | ||
|
||
implicit object `TraversableOnce is Effector` extends Effector[TraversableOnce] { | ||
override def foreach[A](fa: TraversableOnce[A])(f: A ⇒ Any): Unit = fa.foreach(f) | ||
override def foreach[A](fa: TraversableOnce[A])(f: A ⇒ Ui[Any]): Unit = fa.foreach(a ⇒ f(a).run) | ||
} | ||
|
||
implicit object `Option is Effector` extends Effector[Option] { | ||
def foreach[A](fa: Option[A])(f: A ⇒ Any) = fa.foreach(f) | ||
def foreach[A](fa: Option[A])(f: A ⇒ Ui[Any]) = fa.foreach(a ⇒ f(a).run) | ||
} | ||
|
||
implicit object `Try is Effector` extends Effector[Try] { | ||
def foreach[A](fa: Try[A])(f: A ⇒ Any) = fa.foreach(f) | ||
def foreach[A](fa: Try[A])(f: A ⇒ Ui[Any]) = fa.foreach(a ⇒ f(a).run) | ||
} | ||
|
||
implicit def `Future is Effector`(implicit ec: ExecutionContext) = new Effector[Future] { | ||
import macroid.UiThreading.InPlaceFuture | ||
|
||
def foreach[A](fa: Future[A])(f: A ⇒ Any) = fa.foreachInPlace(f) | ||
def foreach[A](fa: Future[A])(f: A ⇒ Ui[Any]) = fa.mapUi(f) | ||
} | ||
} |