Add “array” function for turning a sequence into an array, used after the |> operator.

This commit is contained in:
Kare Morstol
2014-10-23 00:14:10 +02:00
parent 838b5ee617
commit 991da5fd39
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -77,3 +77,8 @@ public func join<C : ExtensibleCollectionType, S : SequenceType where S.Generato
return join(separator, elements)
}
/** Turn a sequence into an array. For use after the |> operator. */
public func array <S : SequenceType, T where S.Generator.Element == T>(sequence: S) -> [T] {
return Array(sequence)
}
+7
View File
@@ -29,4 +29,11 @@ class Pipes_Tests: XCTestCase {
XCTAssertEqual( result, 45 )
}
func testTurnSequenceIntoArray () {
let numbers = [4,1,6]
let result = SequenceOf(numbers) |> array
XCTAssertEqual( result, [4,1,6] )
}
}