SlideShare a Scribd company logo
1 of 60
Download to read offline
ZIO Queue John A. De Goes — @jdegoes - http://degoes.net ScalaWave 2018
ZIO Queue
ScalaWave 2018 - Gdańsk, Poland
John A. De Goes
@jdegoes - http://degoes.net
What is ZIO?
Powered by Queues
Troubled Queues
Introducing ZIO Queue
Wrap Up
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
ZIO
ZIO lets you build
high-performance, type-safe,
concurrent, asynchronous
applications that don’t leak
resources or deadlock, and are
easy to reason about
compositionally, test, and refactor.
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
github.com/scalaz/scalaz-zio
ZIO
def main: Unit = {
println("Hello, what is your name?")
val name = readLine()
println(s"Good morning, $name!")
}
Second-Class Effects
✗ Pass to functions
✗ Return from functions
✗ Store in data structures
✗ Async/sync/concurrency
✓ Resource-safety
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
def main: IO[IOException, Unit] = for {
_ <- putStrLn("Hello, what is your name?")
name <- getStrLn
_ <- putStrLn(s"Good morning, $name!")
} yield ()
First-Class Effects
✓ Pass to functions
✓ Return from functions
✓ Store in data structures
✓ Async/sync/concurrency
✓ Resource-safety
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
IO[E, A]
IO[E, A] is an immutable value that
describes an effectful computation,
which may fail with a value of type E, or
compute a value of type A.
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
def runInParallel[E, A, B](
leftIO : IO[E, A],
rightIO: IO[E, B]): IO[E, (A, B)] =
for {
leftFiber <- leftIO.fork
rightFiber <- rightIO.fork
a <- leftFiber.join
b <- rightFiber.join
} yield (a, b)
Fork/Join Concurrency with Fibers
✓ Massive scalability over threads
✓ Non-blocking
✓ Automatically interruptible
✓ Always resource-safe
✓ Powerful composition
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Powered by Queues
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Producer Consumer
offer take
Queue
1-to-1
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Producer
Consumer
offer take
Queue
Producer
n-to-1
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Producer
Consumer
offer take
Queue
Consumer
1-to-m
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Consumer
offer take
Queue
Consumer
Producer
Producer
n-to-m
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
FIFO
LIFO
PRIO
Bounded
Unbounded
Dropping
Sliding
dimensions of variation
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
queue
actors
send
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
concurrent graph search
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
resource sharing
scarce resource
e.g. threads
Thread 1
take Thread 2offer
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
loose coupling
offer
take
Fast Producers
Slow Consumers
buffer
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Troubled Queues
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
trait BlockingQueue[A] {
def take: A
def offer(a: A): Boolean
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
Blocks one thread
until element added
trait BlockingQueue[A] {
def take: A
def offer(a: A): Boolean
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
Fast Producer Slow Consumer
offer take
Queue
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
Fast Producer Slow Consumer
offer
take
Queue
manual
backpressure
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
def fastProducer = {
if (!queue.offer(a)) {
// Slow down!!!
} else {
// Keep producing...
}
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.BlockingQueue
Fast Producer Slow Consumer
offer
take
Queue
manual
backpressure
manual
backpressure
take
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.ConcurrentLinkedQueue
trait ConcurrentLinkedQueue[A] {
def poll: A
def offer(a: A): Boolean
}
Returns null if empty
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
java.util.concurrent.ConcurrentLinkedQueue
Fast Producer Slow Consumer
offer poll
Queue
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
github.com/scalaz/scalaz-zio
ZIO QUEUE
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
ZIO Queue
trait Queue[A] {
def take: IO[Nothing, A]
def offer(a: A): IO[Nothing, Unit]
def shutdown(ts: Throwable*): IO[Nothing, Unit]
}
object Queue {
def bounded[A](capacity: Int): IO[Nothing, Queue[A]] = ???
def unbounded[A]: IO[Nothing, Queue[A]] = ???
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Example
for {
queue <- Queue.unbounded[String]
_ <- queue.offer("Give me Coffee!").forever.fork
_ <- queue.take.flatMap(putStrLn).forever
} yield ()
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
5. Concurrent
Consumer
offer take
Queue
Consumer
Producer
Producer
ZIO
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
4. Interruptible
for {
queue <- Queue.unbounded[String]
fiber <- queue.offer("Give me Coffee!").forever.fork
_ <- fiber.interrupt
} yield ()
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
3. Clean Shutdown
for {
queue <- Queue.unbounded[String]
fiber1 <- queue.offer("Give me Coffee!").forever.fork
fiber2 <- queue.take.forever.fork
_ <- queue.shutdown
} yield ()
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
2. Asynchronous
for {
queue <- Queue.unbounded[String]
worker = queue.take.flatMap(putStrLn).forever
workers10k = List.fill(10000)(worker)
_ <- IO.forkAll(workers10k)
_ <- queue.offer("More Coffee!").forever.fork
} yield ()
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
2. Asynchronous
trait BlockingQueue[A] {
def take: A ;
def offer(a: A): Boolean
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
1. Composable Backpressure
for {
queue <- Queue.bounded[String](10)
worker = queue.offer("Coffee").forever
workers10k = List.fill(10000)(worker)
_ <- IO.forkAll(workers10k)
_ <- queue.take.flatMap(putStrLn).forever.fork
} yield ()
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
case class Actor[+E, -A, +B](run: A => IO[E, B]) { self =>
def ! (a: A): IO[E, B] = run(a)
}
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]):
IO[Nothing, Actor[E, A, B]] =
for {
state <- Ref(s)
queue <- Queue.bounded[(A, Promise[E, B])](QueueSize)
fiber <- (for {
t <- queue.take
s <- state.get
(a, promise) = t
receiver = receive(s, a)
completer = (s: S, b: B) =>
state.set(s) *> promise.complete(b)
_ <- receiver.redeem(
e => supervise(receiver, e)
.redeem(promise.error, completer), completer)
} yield ()).forever.fork
} yield Actor[E, A, B]((a: A) =>
Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Application: Scalaz Actors
def makeCounter: IO[Nothing, Actor[Nothing, Int, Int]] =
makeActor(Supervisor.logDefects(Logging))(0) {
(state: Int, n: Int) =>
IO.now((state + n, state + n))
}
for {
counter <- makeCounter
_ <- counter ! 40
_ <- counter ! -2
v <- counter ! 0
} yield v
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
WRAP UP
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
github.com/scalaz/scalaz-zio
ZIO CFC
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
ZIO ROADMAP
Performance Sliding Dropping
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
https://gitter.im/scalaz/scalaz/
https://gitter.im/scalaz/scalaz-ioqueue/
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
Functional Scala by John A. De Goes
Local Remote Date
Scotland European Time Sep 10 - 14
Toronto East Coast Time Oct 1 - 5
? European Time Oct 22 - 26
SF / SV Pacific Coast Time Nov 18 -
22
What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
THANK YOU!
@jdegoes - http://degoes.net

More Related Content

What's hot

The Expression Problem - Part 1
The Expression Problem - Part 1The Expression Problem - Part 1
The Expression Problem - Part 1Philip Schwarz
 
Tagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also ProgramsTagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also ProgramsPhilip Schwarz
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOJorge Vásquez
 
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021Natan Silnitsky
 
Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Philip Schwarz
 
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type ClassesJohn De Goes
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaKnoldus Inc.
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaJorge Vásquez
 
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Julien Truffaut
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsPhilip Schwarz
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Edureka!
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Jorge Vásquez
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Philip Schwarz
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
 

What's hot (20)

The Expression Problem - Part 1
The Expression Problem - Part 1The Expression Problem - Part 1
The Expression Problem - Part 1
 
Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
 
Tagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also ProgramsTagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also Programs
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
How to successfully manage a ZIO fiber’s lifecycle - Functional Scala 2021
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1
 
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
 
scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in Scala
 
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and Cats
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
 
Zio in real world
Zio in real worldZio in real world
Zio in real world
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and Fold
 

Similar to ZIO Queue

ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingJohn De Goes
 
Environmental effects - a ray tracing exercise
Environmental effects - a ray tracing exerciseEnvironmental effects - a ray tracing exercise
Environmental effects - a ray tracing exercisePierangelo Cecchetto
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemJohn De Goes
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaWiem Zine Elabidine
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesStephen Chin
 
The report of JavaOne2011 about groovy
The report of JavaOne2011 about groovyThe report of JavaOne2011 about groovy
The report of JavaOne2011 about groovyYasuharu Nakano
 
Scala meetup
Scala meetupScala meetup
Scala meetup扬 明
 
The What, Why And How of ClojureScript
The What, Why And How of ClojureScriptThe What, Why And How of ClojureScript
The What, Why And How of ClojureScriptIvan Bokii
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overviewAndrii Mishkovskyi
 
Orchestrated Chaos: Applying Failure Testing Research at Scale.
Orchestrated Chaos: Applying Failure Testing Research at Scale.Orchestrated Chaos: Applying Failure Testing Research at Scale.
Orchestrated Chaos: Applying Failure Testing Research at Scale.Reactivesummit
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2Zaar Hai
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In SantosFabio Akita
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechtureAnatoly Bubenkov
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...Stephen Chin
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, TwitterOntico
 

Similar to ZIO Queue (20)

ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional ProgrammingZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
 
Fiber supervision in ZIO
Fiber supervision in ZIOFiber supervision in ZIO
Fiber supervision in ZIO
 
Environmental effects - a ray tracing exercise
Environmental effects - a ray tracing exerciseEnvironmental effects - a ray tracing exercise
Environmental effects - a ray tracing exercise
 
Ray tracing with ZIO-ZLayer
Ray tracing with ZIO-ZLayerRay tracing with ZIO-ZLayer
Ray tracing with ZIO-ZLayer
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect System
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in Scala
 
Berlin meetup
Berlin meetupBerlin meetup
Berlin meetup
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
 
The report of JavaOne2011 about groovy
The report of JavaOne2011 about groovyThe report of JavaOne2011 about groovy
The report of JavaOne2011 about groovy
 
Scala meetup
Scala meetupScala meetup
Scala meetup
 
The What, Why And How of ClojureScript
The What, Why And How of ClojureScriptThe What, Why And How of ClojureScript
The What, Why And How of ClojureScript
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
 
Orchestrated Chaos: Applying Failure Testing Research at Scale.
Orchestrated Chaos: Applying Failure Testing Research at Scale.Orchestrated Chaos: Applying Failure Testing Research at Scale.
Orchestrated Chaos: Applying Failure Testing Research at Scale.
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechture
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
 
Zio from Home
Zio from Home Zio from Home
Zio from Home
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, Twitter
 

More from John De Goes

One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them AllJohn De Goes
 
Error Management: Future vs ZIO
Error Management: Future vs ZIOError Management: Future vs ZIO
Error Management: Future vs ZIOJohn De Goes
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }John De Goes
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final TaglessJohn De Goes
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: RebirthJohn De Goes
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: RebirthJohn De Goes
 
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018John De Goes
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New GameJohn De Goes
 
Scalaz 8 vs Akka Actors
Scalaz 8 vs Akka ActorsScalaz 8 vs Akka Actors
Scalaz 8 vs Akka ActorsJohn De Goes
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional ArchitectureJohn De Goes
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
Post-Free: Life After Free Monads
Post-Free: Life After Free MonadsPost-Free: Life After Free Monads
Post-Free: Life After Free MonadsJohn De Goes
 
Streams for (Co)Free!
Streams for (Co)Free!Streams for (Co)Free!
Streams for (Co)Free!John De Goes
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and FutureJohn De Goes
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!John De Goes
 
Getting Started with PureScript
Getting Started with PureScriptGetting Started with PureScript
Getting Started with PureScriptJohn De Goes
 
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
SlamData - How MongoDB Is Powering a Revolution in Visual AnalyticsSlamData - How MongoDB Is Powering a Revolution in Visual Analytics
SlamData - How MongoDB Is Powering a Revolution in Visual AnalyticsJohn De Goes
 
The Next Great Functional Programming Language
The Next Great Functional Programming LanguageThe Next Great Functional Programming Language
The Next Great Functional Programming LanguageJohn De Goes
 

More from John De Goes (20)

One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
 
Error Management: Future vs ZIO
Error Management: Future vs ZIOError Management: Future vs ZIO
Error Management: Future vs ZIO
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: Rebirth
 
Scalaz Stream: Rebirth
Scalaz Stream: RebirthScalaz Stream: Rebirth
Scalaz Stream: Rebirth
 
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New Game
 
Scalaz 8 vs Akka Actors
Scalaz 8 vs Akka ActorsScalaz 8 vs Akka Actors
Scalaz 8 vs Akka Actors
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional Architecture
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Post-Free: Life After Free Monads
Post-Free: Life After Free MonadsPost-Free: Life After Free Monads
Post-Free: Life After Free Monads
 
Streams for (Co)Free!
Streams for (Co)Free!Streams for (Co)Free!
Streams for (Co)Free!
 
MTL Versus Free
MTL Versus FreeMTL Versus Free
MTL Versus Free
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and Future
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!
 
Getting Started with PureScript
Getting Started with PureScriptGetting Started with PureScript
Getting Started with PureScript
 
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
SlamData - How MongoDB Is Powering a Revolution in Visual AnalyticsSlamData - How MongoDB Is Powering a Revolution in Visual Analytics
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
 
The Next Great Functional Programming Language
The Next Great Functional Programming LanguageThe Next Great Functional Programming Language
The Next Great Functional Programming Language
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

ZIO Queue

  • 1. ZIO Queue John A. De Goes — @jdegoes - http://degoes.net ScalaWave 2018 ZIO Queue ScalaWave 2018 - Gdańsk, Poland John A. De Goes @jdegoes - http://degoes.net
  • 2. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 3. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up ZIO ZIO lets you build high-performance, type-safe, concurrent, asynchronous applications that don’t leak resources or deadlock, and are easy to reason about compositionally, test, and refactor.
  • 4. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up github.com/scalaz/scalaz-zio ZIO
  • 5. def main: Unit = { println("Hello, what is your name?") val name = readLine() println(s"Good morning, $name!") } Second-Class Effects ✗ Pass to functions ✗ Return from functions ✗ Store in data structures ✗ Async/sync/concurrency ✓ Resource-safety What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 6. def main: IO[IOException, Unit] = for { _ <- putStrLn("Hello, what is your name?") name <- getStrLn _ <- putStrLn(s"Good morning, $name!") } yield () First-Class Effects ✓ Pass to functions ✓ Return from functions ✓ Store in data structures ✓ Async/sync/concurrency ✓ Resource-safety What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 7. IO[E, A] IO[E, A] is an immutable value that describes an effectful computation, which may fail with a value of type E, or compute a value of type A. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 8. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 9. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 10. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 11. def runInParallel[E, A, B]( leftIO : IO[E, A], rightIO: IO[E, B]): IO[E, (A, B)] = for { leftFiber <- leftIO.fork rightFiber <- rightIO.fork a <- leftFiber.join b <- rightFiber.join } yield (a, b) Fork/Join Concurrency with Fibers ✓ Massive scalability over threads ✓ Non-blocking ✓ Automatically interruptible ✓ Always resource-safe ✓ Powerful composition What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up
  • 12. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Powered by Queues
  • 13. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Producer Consumer offer take Queue 1-to-1
  • 14. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Producer Consumer offer take Queue Producer n-to-1
  • 15. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Producer Consumer offer take Queue Consumer 1-to-m
  • 16. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Consumer offer take Queue Consumer Producer Producer n-to-m
  • 17. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up FIFO LIFO PRIO Bounded Unbounded Dropping Sliding dimensions of variation
  • 18. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up queue actors send
  • 19. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up concurrent graph search
  • 20. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up resource sharing scarce resource e.g. threads Thread 1 take Thread 2offer
  • 21. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up loose coupling offer take Fast Producers Slow Consumers buffer
  • 22. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Troubled Queues
  • 23. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue
  • 24. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue trait BlockingQueue[A] { def take: A def offer(a: A): Boolean }
  • 25. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue Blocks one thread until element added trait BlockingQueue[A] { def take: A def offer(a: A): Boolean }
  • 26. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue Fast Producer Slow Consumer offer take Queue
  • 27. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue Fast Producer Slow Consumer offer take Queue manual backpressure
  • 28. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue def fastProducer = { if (!queue.offer(a)) { // Slow down!!! } else { // Keep producing... } }
  • 29. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.BlockingQueue Fast Producer Slow Consumer offer take Queue manual backpressure manual backpressure take
  • 30. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.ConcurrentLinkedQueue trait ConcurrentLinkedQueue[A] { def poll: A def offer(a: A): Boolean } Returns null if empty
  • 31. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up java.util.concurrent.ConcurrentLinkedQueue Fast Producer Slow Consumer offer poll Queue
  • 32. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up github.com/scalaz/scalaz-zio ZIO QUEUE
  • 33. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up ZIO Queue trait Queue[A] { def take: IO[Nothing, A] def offer(a: A): IO[Nothing, Unit] def shutdown(ts: Throwable*): IO[Nothing, Unit] } object Queue { def bounded[A](capacity: Int): IO[Nothing, Queue[A]] = ??? def unbounded[A]: IO[Nothing, Queue[A]] = ??? }
  • 34. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Example for { queue <- Queue.unbounded[String] _ <- queue.offer("Give me Coffee!").forever.fork _ <- queue.take.flatMap(putStrLn).forever } yield ()
  • 35. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 5. Concurrent Consumer offer take Queue Consumer Producer Producer ZIO
  • 36. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 4. Interruptible for { queue <- Queue.unbounded[String] fiber <- queue.offer("Give me Coffee!").forever.fork _ <- fiber.interrupt } yield ()
  • 37. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 3. Clean Shutdown for { queue <- Queue.unbounded[String] fiber1 <- queue.offer("Give me Coffee!").forever.fork fiber2 <- queue.take.forever.fork _ <- queue.shutdown } yield ()
  • 38. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 2. Asynchronous for { queue <- Queue.unbounded[String] worker = queue.take.flatMap(putStrLn).forever workers10k = List.fill(10000)(worker) _ <- IO.forkAll(workers10k) _ <- queue.offer("More Coffee!").forever.fork } yield ()
  • 39. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 2. Asynchronous trait BlockingQueue[A] { def take: A ; def offer(a: A): Boolean }
  • 40. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up 1. Composable Backpressure for { queue <- Queue.bounded[String](10) worker = queue.offer("Coffee").forever workers10k = List.fill(10000)(worker) _ <- IO.forkAll(workers10k) _ <- queue.take.flatMap(putStrLn).forever.fork } yield ()
  • 41. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors case class Actor[+E, -A, +B](run: A => IO[E, B]) { self => def ! (a: A): IO[E, B] = run(a) }
  • 42. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 43. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 44. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 45. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 46. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 47. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 48. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 49. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 50. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 51. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 52. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 53. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeActor[S, E, A, B](supervisor: Supervisor)(s: S)(receive: (S, A) => IO[E, (S, B)]): IO[Nothing, Actor[E, A, B]] = for { state <- Ref(s) queue <- Queue.bounded[(A, Promise[E, B])](QueueSize) fiber <- (for { t <- queue.take s <- state.get (a, promise) = t receiver = receive(s, a) completer = (s: S, b: B) => state.set(s) *> promise.complete(b) _ <- receiver.redeem( e => supervise(receiver, e) .redeem(promise.error, completer), completer) } yield ()).forever.fork } yield Actor[E, A, B]((a: A) => Promise.make[E, B].flatMap(p => queue.offer((a, p)).flatMap(_ => p.get))
  • 54. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Application: Scalaz Actors def makeCounter: IO[Nothing, Actor[Nothing, Int, Int]] = makeActor(Supervisor.logDefects(Logging))(0) { (state: Int, n: Int) => IO.now((state + n, state + n)) } for { counter <- makeCounter _ <- counter ! 40 _ <- counter ! -2 v <- counter ! 0 } yield v
  • 55. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up WRAP UP
  • 56. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up github.com/scalaz/scalaz-zio ZIO CFC
  • 57. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up ZIO ROADMAP Performance Sliding Dropping
  • 58. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up https://gitter.im/scalaz/scalaz/ https://gitter.im/scalaz/scalaz-ioqueue/
  • 59. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up Functional Scala by John A. De Goes Local Remote Date Scotland European Time Sep 10 - 14 Toronto East Coast Time Oct 1 - 5 ? European Time Oct 22 - 26 SF / SV Pacific Coast Time Nov 18 - 22
  • 60. What is ZIO? Powered by Queues Troubled Queues Introducing ZIO Queue Wrap Up THANK YOU! @jdegoes - http://degoes.net