Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Created December 1, 2022 10:40
Show Gist options
  • Save qingwei91/4f08b5b3a36b85c44f0e6fefb6c09c5a to your computer and use it in GitHub Desktop.
Save qingwei91/4f08b5b3a36b85c44f0e6fefb6c09c5a to your computer and use it in GitHub Desktop.
referential transparent
/**
A piece of code can be replaced by a variable/function that represent itself, in all cases!
*/
val x = 1 + 2
val y = x + x
val z = (1 + 2) + (1+2)
assert(z == y == (x + x))
var mx = 20
var my = { mx += 1; mx * mx }
assert(my != { mx += 1; mx * mx })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment