objcio / functional-swift

Issue repository for the Functional Swift book
http://www.objc.io/books/fpinswift
927 stars 133 forks source link

Why GeneratorType have map method ? #111

Closed cache0928 closed 8 years ago

cache0928 commented 8 years ago

2015-12-31 at 12 18

cache0928 commented 8 years ago

I dont know the meaning of "generator = g.map(anyGenerator)" I cant run this code in playground

justadreamer commented 8 years ago

It's defined elsewhere as an extension on GeneratorType (f.e. see parsing.swift)

extension GeneratorType {
    mutating func map<B>(transform: Element -> B) -> AnyGenerator<B> {
        return anyGenerator {
            self.next().map(transform)
        }
    }
}