# Functional programming in the small, with Swift

DevFeed: [Functional programming in the small, with Swift](<https://devfeed.tech/articles/functional-programming-in-the-small-with-swift-21606.md>)

Original publisher: [Read original article](<http://miqu.me/blog/2015/09/09/functional-programming-in-the-small-with-swift/>)

Author: Miguel Angel Quiñones

Published: 2015-09-09T15:00:23Z

Content type: opinion

Language: en

Sources: [Miguel Quinones](<https://devfeed.tech/sources/miguel-quinones.md>)

Topics: [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [Objective-C](<https://devfeed.tech/topics/objective-c.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [beginner](<https://devfeed.tech/tags/beginner.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [ios](<https://devfeed.tech/tags/ios.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [swift](<https://devfeed.tech/tags/swift.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

The article explains how iOS developers can apply functional programming incrementally in Swift. It recommends using functional techniques in small parts of an application while retaining object-oriented design for the larger structure, and discusses higher-order functions, closures, and trailing-closure syntax.

## Source excerpt

In a previous post, I wrote about the choice of paradigms that Swift presents for it's target audience. I also gave my opinion on how people with different backgrounds might see and approach the Functional Programming paradigm. In this post I want to share how I started to take advantage of FP with Swift for the practical domain of iOS developers: Building apps. Silver bullets In software development there are no silver bullets to kill your problems and move on. We always need to find tradeoffs and evaluate our options to decide what would be the best choice. We often need to consider not only the technical aspects but cultural or team aspects too. iOS applications involve a great deal of UI programming. The iOS frameworks are object-oriented, and Swift is not a pure FP language. Throwing away all the code from Apple's frameworks just to make our code more functional is not a realistic approach. Thus we need to balance where we want to use from different programming paradigms. For a beginner, or a team with not too much experience with FP, my choice would be doing Functional Programming in the small, Object Oriented in the large. FP in the small using Swift Let's look at the features of Swift and the standard library that help write more 'functional' without having to restructure or change how we build a project. Better functions One of the first terms you will hear when diving into FP is that functions are first-class citizens, or the language supports higher-order functions. What this means is that functions are treated like any other type. Think as functions being treated like objects; They can accept other functions as input, return other functions, and be stored and passed around. Under this definition Objective-C kind of supports this, but it's lacking in several areas. Firstly, there's a difference between blocks and selectors, the way to use them is different and the syntax is more complex. Secondly, in Swift a closure is a function without name, and they bo