 	}
 	
 	/// Returns the longest prefix of values in a `Stream` for which a predicate holds.
-	public func takeWhile(p : T -> Bool) -> [T] {
+	public func takeWhile(p : Element -> Bool) -> [Element] {
 		if p(self.step().head) {
 			return self.step().tail.takeWhile(p).cons(self.step().head)
 		}

public struct Stream<Element> {
	private let step : () -> (head : Element, tail : Stream<Element>)
	
	private init(_ step : () -> (head : T, tail : Stream<T>)) {
		self.step = step
	}
	
	/// Uses function to construct a `Stream`.
	///
	/// Unlike unfold for lists, unfolds to construct a `Stream` have no base case.
	public static func unfold<A>(initial : A, _ f : A -> (T, A)) -> Stream<T> {
		let (x, d) = f(initial)
		return Stream { (x, Stream.unfold(d, f)) }
	}
	
	/// Repeats a value into a constant stream of that same value.
	public static func `repeat`(x : T) -> Stream<T> {
		return Stream { (x, `repeat`(x)) }
	}
	
	/// Returns a `Stream` of an infinite number of iteratations of applications of a function to a value.
	public static func iterate(initial : T, _ f : T -> T)-> Stream<T> {
		return Stream { (initial, Stream.iterate(f(initial), f)) }
	}
	
	/// Cycles a non-empty list into an infinite `Stream` of repeating values.
	///
	/// This function is partial with respect to the empty list.
	public static func cycle(xs : [T]) -> Stream<T> {
		switch xs.match {
		case .Nil:
			return error("Cannot cycle an empty list.")

}

extension Stream : SequenceType {
	public typealias Generator = StreamGenerator<Element>
	
	public func generate() -> StreamGenerator<Element> {
		return StreamGenerator(self)
	}
}
