forked from gitpitch/the-template
-
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.
- Loading branch information
Showing
21 changed files
with
537 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
---?color=linear-gradient(to right, #c02425, #f0cb35) | ||
@title[Introduction] | ||
@transition[none] | ||
|
||
@snap[west headline text-white span-70] | ||
Future vs IO | ||
@snap[west] | ||
@css[title-box](Future vs IO) | ||
@snapend | ||
|
||
@snap[south-west byline text-white] | ||
Managing Effects in your Application | ||
@snap[south-west] | ||
@color[#ffffff](Managing Effects In Your Application) | ||
@snapend | ||
|
||
--- | ||
---?include=assets/md/01_effect/PITCHME.md | ||
|
||
<!-- ---?include=template/md/split-screen/PITCHME.md --> | ||
---?include=assets/md/02_future/PITCHME.md | ||
|
||
---?include=assets/md/02a_return/PITCHME.md | ||
|
||
---?include=assets/md/03_io/PITCHME.md | ||
|
||
---?include=assets/md/04_zio/PITCHME.md | ||
|
||
---?include=assets/md/05_inter-op/PITCHME.md | ||
|
||
---?include=assets/md/06_conclusion/PITCHME.md | ||
|
||
|
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,6 +1,6 @@ | ||
# GitPitch - The Template | ||
# Future vs IO | ||
|
||
*THE FASTEST WAY FROM IDEA TO PRESENTATION* | ||
*Managing Effects in Your Applications* | ||
|
||
For details, see the complete template documentation [here](https://gitpitch.com/docs/the-template). | ||
[Presentation](https://gitpitch.com/ASRagab/Future-vs-IO/master#/) | ||
|
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,44 +1,28 @@ | ||
/* Enable List Bullet Icons */ | ||
.reveal ul { list-style: none; } | ||
|
||
/* Enable Huge Icons */ | ||
.fa-huge { font-size : 15em; color: #eba3ff; } | ||
|
||
/* Custom Icons Colors */ | ||
.fa-pink { color : #eba3ff; } | ||
.fa-peach { color : #ffa6b9; } | ||
.fa-orange { color: #fdc200 } | ||
.fa-lime { color : #b9ff66; } | ||
|
||
span.fa-byline { color : gray; } | ||
|
||
.reveal section img { | ||
border: 0; | ||
box-shadow: none; | ||
} | ||
|
||
.reveal pre { | ||
width: 120%; | ||
margin-left: -10%; | ||
} | ||
|
||
.reveal table { | ||
width: 130%; | ||
margin-left: -15%; | ||
.reveal pre code { | ||
font-size: 0.8em; | ||
} | ||
|
||
.reveal h1 { | ||
font-size: 1.55em | ||
} | ||
|
||
.reveal h2 { | ||
font-size: 1.35em | ||
.reveal li { | ||
font-size: 60% | ||
} | ||
|
||
.reveal h3 { | ||
font-size: 1.15em | ||
.title-box { | ||
width: 80%; | ||
border-radius: 20px; | ||
background-color: white; | ||
padding: 20px 20px !important; | ||
} | ||
|
||
.reveal li { | ||
font-size: 70% | ||
.footnote { | ||
color: gray !important; | ||
font-style: italic !important; | ||
font-size: .3em !important; | ||
} |
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,13 @@ | ||
@snap[north] | ||
@color[#eb4500](What's an effect?) | ||
@snapend | ||
|
||
> Anything that you can't do "n + 1" times without irreversible consequences* | ||
- Writing to a database | | ||
- Throwing an exception | | ||
- Logging | | ||
|
||
@snap[south] | ||
@css[footnote](*modulo cpu cycles, entropy and the inexorable march of time) | ||
@snapend |
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,113 @@ | ||
@color[#eb4500](Problems with Future) | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Problems with Future: Setup) | ||
@snapend | ||
|
||
```scala | ||
import java.io.{File, PrintWriter} | ||
|
||
object Helper { | ||
var externalState = 0 | ||
|
||
def writeToFile(path: String): Unit = { | ||
externalState = externalState + 10 | ||
val w = new PrintWriter(new File(path)) | ||
w.write(externalState.toString) | ||
w.close() | ||
} | ||
} | ||
``` | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Referential Opaqueness) | ||
@snapend | ||
|
||
```scala | ||
import Helper._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
val path = "/Users/ahmadragab/Desktop/test.txt" | ||
val fut1 = Future { throw new Exception("Oops!") } | ||
val fut2 = Future { writeToFile(path) } | ||
|
||
val ftr = for { | ||
_ <- fut1 | ||
_ <- fut2 | ||
} yield () | ||
|
||
println(externalState) | ||
Await.result(ftr, Duration.Inf) | ||
``` | ||
|
||
@[5-6](What happens if I make these `lazy`) | ||
@[5-6](What happens if I make these `defs`) | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Referential Opaqueness: Inlined) | ||
@snapend | ||
|
||
```scala | ||
val ftr = for { | ||
_ <- Future { throw new Exception("Oops!") } | ||
_ <- Future { writeToFile(path) } | ||
} yield () | ||
``` | ||
@[4](Does the file get written to the desktop?) | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Memoization Issues) | ||
@snapend | ||
|
||
```scala | ||
lazy val randomFuture = Future.successful { | ||
println("Computing next random Int") | ||
scala.util.Random.nextInt() | ||
} | ||
|
||
println(randomFuture) | ||
println(randomFuture) | ||
``` | ||
@[6-7](How many randoms are produced?) | ||
@[6-7](How many times does "Computing next..." get printed out?) | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Other Challenges with Future) | ||
@snapend | ||
|
||
- Uses JVM Threads | | ||
- Abstractions over early termination missing | | ||
- Fails with Throwable, and only Throwable | | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Exception Handling) | ||
@snapend | ||
|
||
- Handles certain exceptions differently from others | | ||
- TimeoutException i.e. ControlThrowable | | ||
- scala.runtime.NonLocalReturnControl[_] | | ||
- InterruptedException | | ||
|
||
```scala | ||
// Promise.scala | ||
private def resolver[T](throwable: Throwable): Try[T] = throwable match { | ||
case t: scala.runtime.NonLocalReturnControl[_] => Success(t.value.asInstanceOf[T]) // more on this shortly | ||
case t: scala.util.control.ControlThrowable => Failure(new ExecutionException("Boxed ControlThrowable", t)) | ||
case t: InterruptedException => Failure(new ExecutionException("Boxed InterruptedException", t)) | ||
case e: Error => Failure(new ExecutionException("Boxed Error", e)) | ||
case t => Failure(t) | ||
} | ||
``` | ||
|
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,33 @@ | ||
@snap[north] | ||
@color[#eb4500](Return: Off topic rant) | ||
@snapend | ||
|
||
[Don't Use Return in Scala](https://tpolecat.github.io/2014/05/09/return.html) | ||
|
||
```scala | ||
def happy: Int = { | ||
val sumFold: List[Int] => Int = _.foldLeft(0)((n, m) => n + m) // you could just use sum here | ||
sumFold(List(0,1,2)) + sumFold(List(3,4,5)) | ||
} | ||
// scala> happy | ||
// res0: Int = 15 | ||
|
||
def wtf: Int = { | ||
val sumFold: List[Int] => Int = _.foldLeft(0)((n, m) => return n + m) | ||
sumFold(List(0,1,2)) + sumFold(List(3,4,5)) | ||
} | ||
// scala> wtf | ||
// res1: Int = 0 ...ARE YOU NOT ENTERTAINED? | ||
``` | ||
@[13](when evaluated abandons current computation and returns from the `method`) | ||
|
||
+++ | ||
@snap[north] | ||
@color[#eb4500](NLRCs: Abanoned Non-Local Computations) | ||
@snapend | ||
|
||
```scala | ||
case t: scala.runtime.NonLocalReturnControl[_] => Success(t.value.asInstanceOf[T]) | ||
``` | ||
@[1](resolver casts the throwable's underlying value and then wraps it into a `Success`) | ||
@[1](NLRC extends `NoStackTrace`, so...NO. STACK. TRACE.) |
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,76 @@ | ||
@color[#eb4500](Introduction to IO) | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Substitutional Impurity) | ||
@snapend | ||
|
||
#### Why do we say that println is impure? | ||
|
||
```scala | ||
println("Hello World") | ||
// Any => Unit or () | ||
``` | ||
|
||
- It breaks substitution because I cannot replace () with println without changing the effect my program has | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Purity is not enough) | ||
@snapend | ||
|
||
```scala | ||
object Pure { | ||
def println(msg: String) = () => Predef.println(msg) | ||
} | ||
|
||
// Pure.println("IO is cool") is equivalent to () => Predef.println(msg) | ||
``` | ||
|
||
- Thunks EVERYWHERE? | | ||
- At some point we've got to dispatch these actions | | ||
- Also, we'd like some abstractions for different evaluation modes | | ||
- Strict (Eager) | | ||
- Lazy (Synchronous) | | ||
- Asyncronously (Callbacks) | | ||
- Failable (Exceptions) | | ||
|
||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](General Behavior of IO) | ||
@snapend | ||
|
||
- Monad! | | ||
- Capture effects into Data Structures | | ||
- Build description(s) of a program(s) | | ||
- explicit dispatch or invocation mechanism | | ||
- run | | ||
- unsafePerformIO | | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Not all IOs are built the same) | ||
@snapend | ||
|
||
- fs2 and Monix Task | | ||
- All the evaluation modes | | ||
- Performant | | ||
- Tied to the larger framework | | ||
|
||
- Scalaz 7 IO | | ||
- Doesn't really support asynchronous computation (i.e. callbacks) | | ||
- Only lazy effect capturing (cannot strictly evaluate) | | ||
|
||
+++ | ||
|
||
@snap[north] | ||
@color[#eb4500](Better IOs) | ||
@snapend | ||
|
||
- cats-effect [(https://typelevel.org/cats-effect/)](https://typelevel.org/cats-effect/) | ||
- zio [(https://scalaz.github.io/scalaz-zio/)](https://scalaz.github.io/scalaz-zio/) |
Oops, something went wrong.