Consider the Following

Van Simmons

|

3 min read
A sunset that makes the shape of the Swift logo

Consider the Following:
func doubler(_ anInt: Int) -> String {
    "    \(anInt * 2)    "
}
extension String {
    init(doubler anInt: Int) {
        self = "    \(anInt * 2)    "
    }
}

extension Int {
    var doubler: String {
        let anInt = self
        return "    \(anInt * 2)    "
    }
}

"    \(anInt * 2)    "

One of the distinguishing features of functional programming is the widespread use of combinators to construct programs. A combinator is a function which builds program fragments from program fragments; in a sense the programmer using combinators constructs much of the desired program automatically, rather than writing every detail by hand.

extension String {
    init(doublerF anInt: Int) {
        self = Playground.doubler(anInt)
    }
}

extension Int {
    var doublerF: String {
        Playground.doubler(self)
    }
}
Newsletter Form
  • VA ProdOps and Data Quality Engineering
    VA ProdOps and Data Quality Engineering
    See more: VA ProdOps and Data Quality Engineering
    Small orange arrow symbol
  • Where the future is going: sniffing out all of Apple’s clues
    Where the future is going: sniffing out all of Apple’s clues
    See more: Where the future is going: sniffing out all of Apple’s clues
    Small orange arrow symbol
Abstract graffiti-style artwork with vivid colors and dynamic shapes.
Simple Form

Connect with our team.

Error

An error has occured, please try again.

Try again