DEV Community

loading...

Discussion on: Daily Challenge #56 - Coffee Shop

Collapse
citizen428 profile image
Michael Kohl

F#, pattern matching + Option to make it at least a little interesting:

let coffee price =
    price
    |> function
    | 2.2 -> Some "Americano"
    | 2.3 -> Some "Latte"
    | 2.4 -> Some "Flat white"
    | 3.5 -> Some "Filter"
    | _ -> None
    |> Option.map (sprintf "Here is your %s, have a nice day!") 
    |> Option.defaultValue "Sorry, exact change only, try again tomorrow!"
Collapse
olekria profile image
Olek Ria

Just perfect!