forked from typelevel/fs2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR moves `suspend` and `delay` from the `Effect` type class to a new `Suspendable` type class. There are two motivations for doing this: - Exposing `unsafeRunAsync` to any function that requires `suspend` or `delay` gives up a lot of parametricity. - Some type constructors have `Suspendable` instances but do not support value extraction. This came up in the [port of Doobie to FS2](typelevel/doobie#323 (comment)). This [came up on Gitter a while back as well](http://www.gitterforum.com/discussion/scalaz-scalaz-stream?page=143).
- Loading branch information
Showing
9 changed files
with
54 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package fs2.util | ||
|
||
/** | ||
* Monad which supports capturing a deferred evaluation of a by-name `F[A]`. | ||
* | ||
* Evaluation is suspended until a value is extracted, typically via the `unsafeRunAsync` | ||
* method on the related [[Effect]] or [[Async]] type classes. Side-effects that occur | ||
* while evaluating a suspension are evaluated exactly once at the time of extraction. | ||
*/ | ||
trait Suspendable[F[_]] extends Monad[F] { | ||
|
||
/** | ||
* Returns an `F[A]` that evaluates and runs the provided `fa` on each run. | ||
*/ | ||
def suspend[A](fa: => F[A]): F[A] | ||
|
||
/** | ||
* Promotes a non-strict value to an `F`, catching exceptions in the process. | ||
* Evaluates `a` each time the returned effect is run. | ||
*/ | ||
def delay[A](a: => A): F[A] = suspend(pure(a)) | ||
} | ||
|
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
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