Created
September 16, 2018 14:44
-
-
Save m25lazi/51113240a6788a2c6703463c8c5088dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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