Hacker News new | ask | show | jobs
by setr 2095 days ago
The example of...

    static func buildIf(_ value: SettingsConvertible?) -> SettingsConvertible {
        value ?? []
    }
and

    static func buildEither(first: SettingsConvertible) -> SettingsConvertible {
        first
    }

    static func buildEither(second: SettingsConvertible) -> SettingsConvertible {
        second
    }
?

These just return their values -- the only one of note is that buildIf returns the empty array by default, but otherwise this is just defining an if statement to be an if statement.

It gives you however to make an if statement do something other than being an if statement, and that seems... bad.

You could for example define it as

    static func buildEither(first: SettingsConvertible) -> SettingsConvertible {
        []
    }
    static func buildEither(second: SettingsConvertible) -> SettingsConvertible {
        []
    }