1
1
mirror of https://github.com/github/semantic.git synced 2024-12-02 11:23:05 +03:00
semantic/prototype/Doubt/Stream.swift
2015-09-16 11:44:56 -04:00

22 lines
330 B
Swift

public enum Stream<A> {
case Nil
case Cons(A, () -> Stream)
public var uncons: (first: A, rest: Stream)? {
switch self {
case let .Cons(first, rest):
return (first, rest())
default:
return nil
}
}
public var first: A? {
return uncons?.first
}
public var rest: Stream {
return uncons?.rest ?? .Nil
}
}