Skip to content

Instantly share code, notes, and snippets.

@maciejpiotrowski89
Forked from riteshhgupta/swift-snippet-9.swift
Last active February 25, 2017 12:33
Show Gist options
  • Select an option

  • Save maciejpiotrowski89/db1932cb8a71ef4b970bb43cb09f3d68 to your computer and use it in GitHub Desktop.

Select an option

Save maciejpiotrowski89/db1932cb8a71ef4b970bb43cb09f3d68 to your computer and use it in GitHub Desktop.
extension Optional {
// `then` function executes the closure if there is some value
func then(_ handler: (Wrapped) -> Void) {
switch self {
case .some(let wrapped): return handler(wrapped)
case .none: break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment