– Uncle Bob (Robert Martin) “Boolean arguments loudly declare that the function does more than one thing. They are confusing and should be eliminated.”
bookFlight city isPremiumCustomer hasCheckedLuggage preferWindow = let luggageCost = if hasCheckedLuggage then ... else ... in if isPremiumCustomer then if hasCheckedLuggage then ... else ... else if hasCheckedLuggage then ... else ...
– Martin Fowler “…an API should be written to make it easier for the caller, so if we know where the caller is coming from we should design the API with that information in mind.”
findDogByName name dogs = if Dict.member name dogs then case Dict.get name dogs of Just dog -> name ++ " is a " ++ dog.breed Nothing -> "Heck! No pupper found." else "Heck! No pupper found."
findDogByName name dogs = if Dict.member name dogs then case Dict.get name dogs of Just dog -> name ++ " is a " ++ dog.breed Nothing -> "Heck! No pupper found." else "Heck! No pupper found."
findDogByName name dogs = if Dict.member name dogs then case Dict.get name dogs of Just dog -> name ++ " is a " ++ dog.breed Nothing -> "Heck! No pupper found." else "Heck! No pupper found."
canDivide numerator denominator = denominator /= 0 divisionResult numerator denominator = if canDivide numerator denominator then "The result is " ++ toString (numerator / denominator) else "Could not divide"
canDivide numerator denominator = denominator /= 0 divisionResult numerator denominator = if canDivide numerator denominator then "The result is " ++ toString (numerator / denominator) else "Could not divide"
divisionResult numerator denominator = if canDivide numerator denominator then "The result is " ++ toString (numerator / denominator) else "The result is " ++ toString (numerator / denominator)
type TellTime = Time String | NoWatch | NoPhone | NoSundial case whatTimeIsIt person of Time time -> ... NoWatch -> ... NoPhone -> ... NoSundial -> ...
divide numerator denominator = case denominator of 0 -> Err "Divide by zero" _ -> Ok (numerator / denominator) divisionResult numerator denominator = case divide 4 2 of Ok result -> "The result is " ++ toString result Err error -> "Could not divide: " ++ error
view : Model -> Html Msg view model = case model.dog of Ready -> viewFindDog model Fetching -> viewSpinner Success dog -> viewDog dog Error error -> viewError error
view : Model -> Html Msg view model = case model.dog of Ready -> viewFindDog model Fetching -> viewSpinner Success dog -> viewDog dog -- Error error -> viewError error
This `case` does not have branches for all possibilities. 47|> case model.dog of 48|> Ready -> viewFindDog model 49|> 50|> Fetching -> viewSpinner 51|> 52|> Success dog -> viewDog dog You need to account for the following values: Main.Error _ Add a branch to cover this pattern!