Created
June 1, 2015 16:12
-
-
Save griotspeak/d9d826ed242b89ff2d85 to your computer and use it in GitHub Desktop.
Swift.Optional extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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