From 6e85e692839019e9ad45f14523396baac5e4fa58 Mon Sep 17 00:00:00 2001 From: codestergit Date: Sun, 6 Dec 2015 04:01:33 +0530 Subject: [PATCH] [stdlib] Using map and guard let for nil handling --- stdlib/public/core/Algorithm.swift | 5 ++--- stdlib/public/core/Collection.swift | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/stdlib/public/core/Algorithm.swift b/stdlib/public/core/Algorithm.swift index 770971bec5bb9..6448278326143 100644 --- a/stdlib/public/core/Algorithm.swift +++ b/stdlib/public/core/Algorithm.swift @@ -177,9 +177,8 @@ public struct EnumerateGenerator< /// /// - Requires: No preceding call to `self.next()` has returned `nil`. public mutating func next() -> Element? { - let b = base.next() - if b == nil { return .None } - return .Some((index: count++, element: b!)) + guard let b = base.next() else { return .None } + return .Some((index: count++, element: b)) } } diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift index ecee5d30fe368..9501ad70020ef 100644 --- a/stdlib/public/core/Collection.swift +++ b/stdlib/public/core/Collection.swift @@ -765,8 +765,7 @@ public struct PermutationGenerator< /// /// - Requires: No preceding call to `self.next()` has returned `nil`. public mutating func next() -> Element? { - let result = indices.next() - return result != nil ? seq[result!] : .None + return indices.next().map { seq[$0] } } /// Construct a *generator* over a permutation of `elements` given