Skip to content

Instantly share code, notes, and snippets.

@griotspeak
Created June 1, 2015 16:12
Show Gist options
  • Save griotspeak/d9d826ed242b89ff2d85 to your computer and use it in GitHub Desktop.
Save griotspeak/d9d826ed242b89ff2d85 to your computer and use it in GitHub Desktop.
Swift.Optional extensions
//
// Optional.swift
// TonalKit
//
// Created by TJ Usiyan on 11/4/14.
// Copyright (c) 2014 Buttons and Lights LLC. All rights reserved.
// https://gist.github.com/d9d826ed242b89ff2d85.git
extension Optional {
internal func bind<U>(f: T -> U?) -> U? {
if let x = self {
return f(x)
} else {
return nil
}
}
}
func mapSome<S: SequenceType, T: ExtensibleCollectionType>
(source: S, transform: (S.Generator.Element)->T.Generator.Element?) -> T {
var result = T()
for x in source {
if let y = transform(x) {
result.append(y)
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment