Swift: Lazily encapsulating chains of map, filter, flatMap
I have a list of animals: let animals = ["bear", "dog", "cat"] And some ways to transform that list: typealias Transform = (String) -> [String] let containsA: Transform = { $0.contains("a") ? [$0] : [] } let plural: Transform = { [$0 + "s"] } let double: Transform = { [$0, $0] } As a slight aside, these are analogous to filter (outputs 0 or 1 element), map (exactly 1 element) and flatmap (more than 1 element) respectively but defined in a uniform way so that they can be handled consistently. I want to create a lazy iterator which applies an array of these transforms to the list of animals: