import Foundation

enum LandingFeatures {
  /// Features in ascending order of date
  static let features: [LandingFeature?] = [
    LandingFeatures.introToProgramming1,
    LandingFeatures.introToProgramming2,
    LandingFeatures.bashWorkshop,
    LandingFeatures.gitWorkshop,
    LandingFeatures.introToProgramming3,
    LandingFeatures.programmingInRust,
    LandingFeatures.introToProgramming4,
    LandingFeatures.binaryExploitation,
    LandingFeatures.gamesWithLove,
    LandingFeatures.gameGig,
    LandingFeatures.introToUnity,
    LandingFeatures.continuousIntegrationWorkshop
  ]

  /// Gets the most currently appropriate feature
  static var currentFeature: LandingFeature? {
    let currentDate = Date()

    // We want to return the first non-nil LandingFeature whos expiry date is
    // after the current date. As the list itself is a list of optionals, we
    // need to convert it to a list of non-optionals using flatMap first (as
    // otherwise a value of type double-optional is returned.)
    return  features.flatMap{ $0 }.first { $0.expiryDate > currentDate }
  }
}

import Foundation

enum LandingFeatures {
  /// Features in ascending order of date
  static let features: [LandingFeature?] = [
    LandingFeatures.introToProgramming1,
    LandingFeatures.introToProgramming2,
    LandingFeatures.bashWorkshop,
    LandingFeatures.gitWorkshop,
    LandingFeatures.introToProgramming3,
    LandingFeatures.programmingInRust,
    LandingFeatures.introToProgramming4,
    LandingFeatures.binaryExploitation,
    LandingFeatures.gamesWithLove,
    LandingFeatures.gameGig,
    LandingFeatures.introToUnity,
    LandingFeatures.continuousIntegrationWorkshop
  ]

  /// Gets the most currently appropriate feature
  static var currentFeature: LandingFeature? {
    let currentDate = Date()

    // We want to return the first non-nil LandingFeature whos expiry date is
    // after the current date. As the list itself is a list of optionals, we
    // need to safely unwrap the result at least once as features.first returns
    // a double optional.
    return (
      features.first { $0?.expiryDate ?? currentDate > currentDate }
      ?? nil
    )
  }
}

--- 
+++ 
@@ -23,11 +23,8 @@
 
     // We want to return the first non-nil LandingFeature whos expiry date is
     // after the current date. As the list itself is a list of optionals, we
-    // need to safely unwrap the result at least once as features.first returns
-    // a double optional.
-    return (
-      features.first { $0?.expiryDate ?? currentDate > currentDate }
-      ?? nil
-    )
+    // need to convert it to a list of non-optionals using flatMap first (as
+    // otherwise a value of type double-optional is returned.)
+    return  features.flatMap{ $0 }.first { $0.expiryDate > currentDate }
   }
 }
Make optional unwrapping for landing features less confusing
