Skip to content

Instantly share code, notes, and snippets.

@djryanash
Created May 12, 2023 03:57
Show Gist options
  • Save djryanash/a43e20bccaeb998d17d30dbebc20519a to your computer and use it in GitHub Desktop.
Save djryanash/a43e20bccaeb998d17d30dbebc20519a to your computer and use it in GitHub Desktop.
A neat and readable way of evaluating multiple Bool conditions
import Foundation
struct AnyStruct {
func isUserEligible(age: Int, city: String, income: Int, educationLevel: String) {
let isAgeElig: Bool = age >= 18
let isCityElig: Bool = city == "New York" || city == "Los Angeles" || city == "Miami"
let isIncomeElig: Bool = income >= 40_000 && income <= 100_000
let isEduLevelElig: Bool = educationLevel == "Bachelors" || educationLevel == "Masters"
let isEligible: Bool = isAgeElig && isCityElig && isIncomeElig && isEduLevelElig
print(isEligible)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment