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.

Revisions

  1. maciejpiotrowski89 renamed this gist Feb 25, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @riteshhgupta riteshhgupta created this gist Feb 6, 2017.
    10 changes: 10 additions & 0 deletions swift-snippet-9.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@

    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
    }
    }
    }