Skip to content

Instantly share code, notes, and snippets.

@lewisjkl
Last active January 5, 2020 13:53
Show Gist options
  • Save lewisjkl/2fe7d3b190a01836d7ef82f17c093c40 to your computer and use it in GitHub Desktop.
Save lewisjkl/2fe7d3b190a01836d7ef82f17c093c40 to your computer and use it in GitHub Desktop.
Expressions using Future are often not referentially transparent.
val printStuff: Future[Unit] = Future(println("Hello, World!"))
for {
_ <- printStuff
_ <- printStuff
} yield ()
// prints "Hello, World!" once
for {
_ <- Future(println("Hello, World!"))
_ <- Future(println("Hello, World!"))
} yield ()
// prints "Hello, World!" twice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment