and the Laws of Physics
Vending machine
Queuing people
Processor
Threads
1 + 2 + 3 + 4
1 + 2 + 3 + 4
(1 + 2) + (3 + 4)
3 + 7
10
It doesn't matter
1 + 2 + 3 + 4
(1 + 2) + 3 + 4
(3 + 3) + 4
6 + 4
10
Stream(1)
.repeat
.debug()
.take(3)
.compile
.toList
Stream.eval(IO.pure(1))
.repeat
.debug()
.take(3)
.compile
.toList
.unsafeRunSync()
Stream(1)
.repeat
.debug()
.take(3)
.compile
.drain
Stream.eval(IO.pure(1))
.repeat
.debug()
.take(3)
.compile
.drain
.unsafeRunSync()
1
1
1
1
1
1
1
IO.println("Hello") >> IO.println("world")
If B happened, it happened after A
Enforced by IO
IO.println("Hello") >> IO.println("world")
val program = IO.println("Hello") >> IO.println("world")
val fiber = program.start
fiber >>= (_.cancel)
val program = Resource.make(IO.println("Hello")) { _ =>
IO.println("world")
}
resource.use { program =>
val fiber = program.start
fiber >>= (_.cancel)
}
 If A happens, B must happen
Enforced with resources