-
Notifications
You must be signed in to change notification settings - Fork 30
/
ContainerExtensions.swift
45 lines (37 loc) · 1.06 KB
/
ContainerExtensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// ContainerExtensions.swift
// XcodeServerSDK
//
// Created by Honza Dvorsky on 21/06/2015.
// Copyright © 2015 Honza Dvorsky. All rights reserved.
//
import Foundation
extension SequenceType {
func mapThrows<T>(@noescape transform: (Self.Generator.Element) throws -> T) rethrows -> [T] {
var out: [T] = []
for i in self {
out.append(try transform(i))
}
return out
}
func filterThrows(@noescape includeElement: (Self.Generator.Element) throws -> Bool) rethrows -> [Self.Generator.Element] {
var out: [Self.Generator.Element] = []
for i in self {
if try includeElement(i) {
out.append(i)
}
}
return out
}
/**
Basically `filter` that stops when it finds the first one.
*/
func findFirst(@noescape test: (Self.Generator.Element) -> Bool) -> Self.Generator.Element? {
for i in self {
if test(i) {
return i
}
}
return nil
}
}