From c04cd0d84be9a8fc4e1fea89e645b930106a3b4e Mon Sep 17 00:00:00 2001 From: Kare Morstol Date: Fri, 24 Oct 2014 20:26:00 +0200 Subject: [PATCH] =?UTF-8?q?Add=20function=20=E2=80=9Cdrop=E2=80=9D=20for?= =?UTF-8?q?=20discarding=20elements=20from=20a=20sequence.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftShell/Pipes.swift | 9 +++++++++ SwiftShellTests/Pipes_Tests.swift | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/SwiftShell/Pipes.swift b/SwiftShell/Pipes.swift index 0c29628..a1f546a 100644 --- a/SwiftShell/Pipes.swift +++ b/SwiftShell/Pipes.swift @@ -82,3 +82,12 @@ public func join(sequence: S) -> [T] { return Array(sequence) } + +/** Discard all elements in `tobedropped` from sequence. */ +public func drop + (tobedropped: [T]) + (sequence: S) + -> LazySequence> { + + return sequence |> filter { !contains(tobedropped, $0) } +} diff --git a/SwiftShellTests/Pipes_Tests.swift b/SwiftShellTests/Pipes_Tests.swift index 4d9cb02..1ce509e 100644 --- a/SwiftShellTests/Pipes_Tests.swift +++ b/SwiftShellTests/Pipes_Tests.swift @@ -36,4 +36,12 @@ class Pipes_Tests: XCTestCase { XCTAssertEqual( result, [4,1,6] ) } + + func testDrop () { + let numbers = [1,2,3,4,5,6] + + let result = numbers |> drop([2,3,5]) |> toArray + + XCTAssertEqual( result, [1,4,6] ) + } }