Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created November 23, 2015 16:06
Show Gist options
  • Select an option

  • Save kristopherjohnson/67b56c1b07528df1efc7 to your computer and use it in GitHub Desktop.

Select an option

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