Prefer flatMap to guard when chaining values

This commit is contained in:
Gwendal Roué committed 2016-10-08 16:56:39 +02:00
1 parent 027b1f711c
commit 591197422d
1 file changed
+1 -4
@@ -22,9 +22,6 @@ public extension RawRepresentable where Self: DatabaseValueConvertible, Self.Raw
/// Returns a value initialized from *databaseValue*, if possible.
static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Self? {
guard let rawValue = RawValue.fromDatabaseValue(databaseValue) else {
return nil
}
return self.init(rawValue: rawValue)
return RawValue.fromDatabaseValue(databaseValue).flatMap { self.init(rawValue: $0) }
}
}