Skip to content

Commit 8bba74e

Browse files
committed
Merge pull request #241 from codestergit/master
[stdlib] Used map and guard for nil handling
2 parents 403b46c + 6e85e69 commit 8bba74e

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Diff for: stdlib/public/core/Algorithm.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ public struct EnumerateGenerator<
177177
///
178178
/// - Requires: No preceding call to `self.next()` has returned `nil`.
179179
public mutating func next() -> Element? {
180-
let b = base.next()
181-
if b == nil { return .None }
182-
return .Some((index: count++, element: b!))
180+
guard let b = base.next() else { return .None }
181+
return .Some((index: count++, element: b))
183182
}
184183
}
185184

Diff for: stdlib/public/core/Collection.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,7 @@ public struct PermutationGenerator<
765765
///
766766
/// - Requires: No preceding call to `self.next()` has returned `nil`.
767767
public mutating func next() -> Element? {
768-
let result = indices.next()
769-
return result != nil ? seq[result!] : .None
768+
return indices.next().map { seq[$0] }
770769
}
771770

772771
/// Construct a *generator* over a permutation of `elements` given

0 commit comments

Comments
 (0)