From b3c0e92d2afed0e47e4783446345e8a7f062a941 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 17 Sep 2015 14:14:01 -0400 Subject: [PATCH] Stream concatenation. --- prototype/Doubt/Stream.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/prototype/Doubt/Stream.swift b/prototype/Doubt/Stream.swift index a2db8b054..d81142b05 100644 --- a/prototype/Doubt/Stream.swift +++ b/prototype/Doubt/Stream.swift @@ -41,6 +41,16 @@ public enum Stream: NilLiteralConvertible, SequenceType { } + public func concat(other: Stream) -> Stream { + switch self { + case .Nil: + return other + case let .Cons(first, rest): + return .Cons(first, rest.map { $0.concat(other) }) + } + } + + public init(nilLiteral: ()) { self = .Nil }