V. N. Nikhil Anurag
Call 1
Email 1/2
Prep Food
Call 2
Email 2/2
Eat Food
You
Call 1
Email 1/2
Eat Food
You
Call 2
Prep Food
Eat Food
Friend
Call 3
Email 2/2
Concurrency
Parallelism
Call 1
Email 1/2
Prep Food
Call 2
Email 2/2
Eat Food
def get_meaning_of_everything():
do_async() # Might never be run
return 42
Call 1
Email 1/2
Prep Food
Call 2
Email 2/2
You: Core #1
Friend: Core #2
Global
Run
queue
func get_meaning_of_everything() {
go do_async() // Might never run
return 42
}
Execute Sequentially: tasks.mapN(...)
Execute by Composition: task1.flatMap{ res1 => task2.flatMap{...} }
Execute in Parallel: tasks.parMapN(...)
def get_meaning_of_everything_bad() = {
do_async() // Not conventional FP code!
Task(42)
}
def get_meaning_of_everything() = {
do_async().flatMap{ _ =>
Task(42)
}
}
Be the change you want to see in the world
object Mutable {
var mutX = 0
def incrementX() = { mutX += 1 }
}
object Immutable {
val incrementX = State[Int, Int] { state =>
(state + 1, state)
}
}
val (state, oldState) = Immutable.incrementX.run(10).value
# Cores
OS Threads
JVM Threads
Thread Pool
Fibers
Tasks
def get_answer_to_everything[F[_]: Effect](): F[Int] = {
do_async().flatMap{ _ =>
Effect[F].pure(42)
}
}