Created
November 23, 2015 16:06
-
-
Save kristopherjohnson/67b56c1b07528df1efc7 to your computer and use it in GitHub Desktop.
For a Swift SequenceType, return a lazy sequence of elements that conform to a specified type
This file contains hidden or 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
| import Foundation | |
| extension SequenceType { | |
| /// Return a lazy sequence of elements of this sequence that are of type T | |
| func asLazySequence<T>() -> LazyMapSequence<LazyFilterSequence<Self>, T> { | |
| return self.lazy.filter{ $0 is T }.map{ $0 as! T } | |
| } | |
| /// Return a lazy sequence of the elements that are NSDictionary instances | |
| func asLazyNSDictionarySequence() | |
| -> LazyMapSequence<LazyFilterSequence<Self>, NSDictionary> | |
| { | |
| return asLazySequence() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment