diff --git a/README.md b/README.md index 800cce9..eca23b7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,23 @@ for line in open(filename).lines() { } ``` +#### List all executables in PATH + +```swift +let directories = environment["PATH"]!.split(":") +for directory in directories { + run("find \"\(directory)\" -type f -perm +ugo+x -print") |> standardoutput +} +``` + +or in a Functional Programming style: + +```swift +environment["PATH"]! |> split(":") + |> map { dir in run("find \"\(dir)\" -type f -perm +ugo+x -print") } + |> standardoutput +``` + #### Print standard input with line numbers ```swift @@ -42,15 +59,6 @@ for line in standardinput.lines() { Launch with e.g. `ls | print_linenumbers.swift` -#### List all executables in PATH - -```swift -let directories = environment["PATH"]!.split(":") -for directory in directories { - run("find \"\(directory)\" -type f -perm +ugo+x -print") |> standardoutput -} -``` - ## Installation - In the Terminal, go to where you want to download SwiftShell. diff --git a/SwiftShell/Stream.swift b/SwiftShell/Stream.swift index e597a2a..9930ffb 100644 --- a/SwiftShell/Stream.swift +++ b/SwiftShell/Stream.swift @@ -163,16 +163,19 @@ public func |> (lhs: ReadableStreamType, rhs: WriteableStreamType) { } } -/** -Writes something Printable to a writable stream. -*/ +/** Writes something Printable to a writable stream. */ public func |> (lhs: Printable, rhs: WriteableStreamType) { rhs.write(lhs.description) } -/** -Writes a String to a writable stream. -*/ +/** Writes a String to a writable stream. */ public func |> (lhs: String, rhs: WriteableStreamType) { rhs.write(lhs) } + +/** Writes a sequence of streams to another stream. */ +public func |> (lhs: S, rhs: WriteableStreamType) { + for stream in lhs { + stream |> rhs + } +} diff --git a/SwiftShellTests/Scripts/listallexecutablesinpath.swift b/SwiftShellTests/Scripts/listallexecutablesinpath.swift index a1126bb..4608647 100755 --- a/SwiftShellTests/Scripts/listallexecutablesinpath.swift +++ b/SwiftShellTests/Scripts/listallexecutablesinpath.swift @@ -2,8 +2,14 @@ import SwiftShell +/* let directories = environment["PATH"]!.split(":") for directory in directories { run("find \"\(directory)\" -type f -perm +ugo+x -print") |> standardoutput } +*/ + +environment["PATH"]! |> split(":") + |> map { directory in run("find \"\(directory)\" -type f -perm +ugo+x -print") } + |> standardoutput