Skip to content
A playground to introduce Functors in Swift, and their practical usage. From my Melbour CocoaHeads #85 lighting talk.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Functors in Swift - A simple introduction

Note: This Playground is written in Swift 2.0 and Xcode 7 Beta 3.

This is the playground for my lightning talk at July's 2015 Melbourne CocoaHeads.

The talk is a simple introduction to Functors and Monads in Swift, focusing on the practical use of these concepts, rather than their mathematical definition.

The cool things about Functors and Monads are map and flatMap. Using these we can simplify code like this:

func getFancyEmojiForUser() -> String? {
  if let actuallyAUser = userFromDatabase() {
    let joinedUserName = joinedName(actuallyAUser)

    if let emojiForUser = emojiFromString(joinedUserName) {
      return fancifyEmoji(emojiForUser)

  return .None

into something that is easier to write and specially easier to reason about.

func getFancyEmojiForUser() -> String? {
  return userFromDatabase()

If you are interested in this tweet me @mokagio or visit mokacoding

(c) 2015 - Giovanni Lodi

You can’t perform that action at this time.