and the Laws of Physics
Vending machine
Queuing people
Processor
Threads
1 + 2 + 3 + 41 + 2 + 3 + 4
(1 + 2) + (3 + 4)
3 + 7
10It doesn't matter
1 + 2 + 3 + 4
(1 + 2) + 3 + 4
(3 + 3) + 4
6 + 4
10Stream(1)
.repeat
.debug()
.take(3)
.compile
.toListStream.eval(IO.pure(1))
.repeat
.debug()
.take(3)
.compile
.toList
.unsafeRunSync()Stream(1)
.repeat
.debug()
.take(3)
.compile
.drainStream.eval(IO.pure(1))
.repeat
.debug()
.take(3)
.compile
.drain
.unsafeRunSync()1
1
1
11
1
1IO.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