mirror of
https://github.com/github/semantic.git
synced 2024-12-02 11:23:05 +03:00
22 lines
330 B
Swift
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
|
|
}
|
|
}
|