 import Foundation
 
 // Generates values from a closure that invokes a "yield" function
-struct YieldGenerator<T>: Generator {
-    var _yieldedValues = Array<T>()
-    var _index = 0
+public struct YieldGenerator<T>: Generator {
+    private var yieldedValues = Array<T>()
+    private var index = 0
     
-    mutating func _yield(value: T) {
-        _yieldedValues.append(value)
+    private mutating func yield(value: T) {
+        yieldedValues.append(value)
     }
     
-    init(_ yielder: ((T) -> ()) -> ()) {
-        yielder(_yield)
+    public init(_ yielder: ((T) -> ()) -> ()) {
+        yielder(yield)
     }
     
-    mutating func next() -> T? {
-        return _index < _yieldedValues.count ? _yieldedValues[_index++] : nil
+    public mutating func next() -> T? {
+        return index < yieldedValues.count ? yieldedValues[index++] : nil
     }
 }
 



// Create a sequence from a closure that invokes a "yield" function
func sequence<T>(yielder: ((T) -> ()) -> ()) -> SequenceOf<T> {
    return SequenceOf<T>({YieldGenerator(yielder)})
}


//
// The yielder closure is executed on another thread, and each call to yield()
// will block until next() is called by the generator's thread.
public struct LazyYieldGenerator<T>: Generator {
    private var _task: LazyYieldTask<T>?
    private let _yielder: ((T) -> ()) -> ()
    
    public init(_ yielder: ((T) -> ()) -> ()) {
        _yielder = yielder
    }
    
    public mutating func next() -> T? {
        if !_task {
            _task = LazyYieldTask(_yielder)
        }
