From 6350fda52ab95b81ca30be7a0b79373cd636bd77 Mon Sep 17 00:00:00 2001 From: Kare Morstol Date: Thu, 28 Aug 2014 02:17:27 +0200 Subject: [PATCH] Something like 'run("ls") |> standardoutput' now works --- SwiftShell/Pipes.swift | 11 ++++++++--- SwiftShellTests/Scripts/Stream out.swift | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 SwiftShellTests/Scripts/Stream out.swift diff --git a/SwiftShell/Pipes.swift b/SwiftShell/Pipes.swift index 9e8a4ec..dbe84b9 100644 --- a/SwiftShell/Pipes.swift +++ b/SwiftShell/Pipes.swift @@ -26,20 +26,25 @@ public func |> (lhs: T, rhs:((T,V) -> U, V)) -> U { } */ -/* crashes the compiler (beta 6) +/* crashes the compiler (beta 6). +Should replace the function below as it is more general and will also work with strings. + public func |> (lhs: Streamable, inout rhs: OutputStreamType) { + + // specifically its these that crash the compiler, not the function definition. // lhs.writeTo(&rhs) - // rhs.write(lhs.read()) + // rhs.write(lhs.) // print(lhs, &rhs) } */ + /** Prints one stream to another. readablestream |> writablestream */ -public func |> (lhs: ReadableStreamType, inout rhs: WriteableStreamType) { +public func |> (lhs: ReadableStreamType, rhs: WriteableStreamType) { rhs.write(lhs.read()) } diff --git a/SwiftShellTests/Scripts/Stream out.swift b/SwiftShellTests/Scripts/Stream out.swift new file mode 100644 index 0000000..5097ec1 --- /dev/null +++ b/SwiftShellTests/Scripts/Stream out.swift @@ -0,0 +1,4 @@ + +import SwiftShell + +run("ls") |> standardoutput