Skip to content

Instantly share code, notes, and snippets.

@m25lazi
Created September 16, 2018 14:44
Show Gist options
  • Save m25lazi/51113240a6788a2c6703463c8c5088dd to your computer and use it in GitHub Desktop.
Save m25lazi/51113240a6788a2c6703463c8c5088dd to your computer and use it in GitHub Desktop.
// Pure function
func sum(_ num1: Int, _ num2: int) -> Int {
return num1 + num2
}
// Impure function
var accumulated = 0
func add(_ num: Int) -> Int {
accumulated = num + accumulated
return accumulated
}
// Pure class
struct Accumulator {
var value: Int
// Still impure function
func add(_ num: Int) -> Int {
value = num + value
return value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment