This indentation was brought to you by Xcode (6.1).
This commit is contained in:
+21
-21
@@ -21,25 +21,25 @@ public func |> <T,U>(lhs: T, rhs: T -> U) -> U {
|
||||
}
|
||||
|
||||
/** Lazily return a sequence containing the elements of source, in order, that satisfy the predicate includeElement */
|
||||
public func filter <S : SequenceType>
|
||||
public func filter <S : SequenceType>
|
||||
(includeElement: (S.Generator.Element) -> Bool)
|
||||
(source: S)
|
||||
-> LazySequence<FilterSequenceView<S>> {
|
||||
|
||||
|
||||
return lazy(source).filter(includeElement)
|
||||
}
|
||||
|
||||
/**
|
||||
Return an `Array` containing the sorted elements of `source` according to 'isOrderedBefore'.
|
||||
Return an `Array` containing the sorted elements of `source` according to 'isOrderedBefore'.
|
||||
|
||||
Requires: `isOrderedBefore` is a `strict weak ordering
|
||||
Requires: `isOrderedBefore` is a `strict weak ordering
|
||||
<http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>` over `elements`.
|
||||
*/
|
||||
public func sorted <S : SequenceType>
|
||||
(isOrderedBefore: (S.Generator.Element, S.Generator.Element) -> Bool)
|
||||
(source: S)
|
||||
-> [S.Generator.Element] {
|
||||
|
||||
|
||||
return sorted(source, isOrderedBefore)
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ public func map <S: SequenceType, T>
|
||||
(transform: (S.Generator.Element) -> T)
|
||||
(source: S)
|
||||
-> LazySequence<MapSequenceView<S, T>> {
|
||||
|
||||
|
||||
return lazy(source).map(transform)
|
||||
}
|
||||
|
||||
/**
|
||||
Return the result of repeatedly calling combine with an accumulated value
|
||||
/**
|
||||
Return the result of repeatedly calling combine with an accumulated value
|
||||
initialized to initial and each element of sequence, in turn.
|
||||
*/
|
||||
public func reduce <S : SequenceType, U>
|
||||
(initial: U, combine: (U, S.Generator.Element) -> U)
|
||||
(sequence: S)
|
||||
-> U {
|
||||
|
||||
|
||||
return reduce(sequence, initial, combine)
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ public func split (_ delimiter: String = "\n")(text: String) -> [String] {
|
||||
/** Insert separator between each item in elements. */
|
||||
public func join <C : ExtensibleCollectionType, S : SequenceType where S.Generator.Element == C>
|
||||
(separator: C)
|
||||
(elements: S)
|
||||
(elements: S)
|
||||
-> C {
|
||||
|
||||
|
||||
return join(separator, elements)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T
|
||||
(tobedropped: [T])
|
||||
(sequence: S)
|
||||
-> LazySequence<FilterSequenceView<S>> {
|
||||
|
||||
|
||||
return sequence |> filter { !contains(tobedropped, $0) }
|
||||
}
|
||||
|
||||
@@ -96,14 +96,14 @@ public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T
|
||||
public func take <S : SequenceType, T where S.Generator.Element == T>
|
||||
(numbertotake: Int)(sequence: S) -> [T] {
|
||||
|
||||
var generator = sequence.generate()
|
||||
var result = [T]()
|
||||
for _ in 0..<numbertotake {
|
||||
if let value = generator.next() {
|
||||
result.append(value)
|
||||
} else {
|
||||
break
|
||||
var generator = sequence.generate()
|
||||
var result = [T]()
|
||||
for _ in 0..<numbertotake {
|
||||
if let value = generator.next() {
|
||||
result.append(value)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ extension String {
|
||||
public func replace (replaceOldString: String, _ withString: String) -> String {
|
||||
return self.stringByReplacingOccurrencesOfString(replaceOldString, withString: withString)
|
||||
}
|
||||
|
||||
|
||||
public func split (sep: String) -> [String] {
|
||||
return self.componentsSeparatedByString(sep)
|
||||
}
|
||||
|
||||
|
||||
public func trim () -> String {
|
||||
return self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
|
||||
}
|
||||
@@ -42,17 +42,17 @@ extension String {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
Split the string at the first occurrence of separator, and return a 3-tuple containing the part
|
||||
before the separator, the separator itself, and the part after the separator. If the separator is
|
||||
not found, return a 3-tuple containing the string itself, followed by two empty strings.
|
||||
not found, return a 3-tuple containing the string itself, followed by two empty strings.
|
||||
*/
|
||||
public func partition (separator: String) -> (String, String, String) {
|
||||
if let separatorRange = self.rangeOfString(separator) {
|
||||
if !separatorRange.isEmpty {
|
||||
let firstpart = self[self.startIndex ..< separatorRange.startIndex]
|
||||
let secondpart = self[separatorRange.endIndex ..< self.endIndex]
|
||||
|
||||
|
||||
return (firstpart, separator, secondpart)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// String_Tests.swift
|
||||
// SwiftShell
|
||||
// String_Tests.swift
|
||||
// SwiftShell
|
||||
//
|
||||
// Created by Kåre Morstøl on 04.11.14.
|
||||
// Copyright (c) 2014 NotTooBad Software. All rights reserved.
|
||||
// Created by Kåre Morstøl on 04.11.14.
|
||||
// Copyright (c) 2014 NotTooBad Software. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
Reference in New Issue
Block a user