Functional programming in Swift