I need a function that returns a lazy generator of various composed generator functions such as filter and map. For example, if I want to apply lazy.filter().map()
the code looks like:
// Simplified
typealias MyComplexType = Int
typealias MyComplexCollection = [MyComplexType]
func selection() -> LazyMapCollection<LazyFilterCollection<MyComplexCollection>, Int> {
let objects:MyComplexCollection = [1, 2, 3, 4, 5, 6]
let result = objects.lazy.filter({$0 < 4}).map({$0 * 10})
return result
}
for obj in someObjects() {
print(obj)
}
Is there a more generic way to specify the LazyMapCollection<LazyFilterCollection<MyComplexCollection>, Int>
? I tried LazyGenerator<MyComplexCollection>
but I'm getting type incompatibility error. Chaining more lazy functions would make the type even more complex. Better and more appropriate for my needs would be to have a type similar to just LazySomething<MyComplexType>
.