Guest User

Untitled

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