Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Higher order functions, being curried. Considered pure functional, because they don't have any side effects
- // (mutate any given data). They just derive data from data.
- let plus = { (first: Int) in { (second: Int) in first + second } }
- let multiplesOf = { (first: Int) in { (second: Int) in second % first != 0 } }
- // Just a simple first class function, not per se functional. Usable to reduce a collection of integers into the total.
- let total: (Int, Int) -> Int = { $0 + $1 }
- let calculation = (1...30)
- .map(plus(2))
- .filter(multiplesOf(5))
- .reduce(0, total)
- print("\(calculation) vape nationnn")
Add Comment
Please, Sign In to add comment