Skip to content

Instantly share code, notes, and snippets.

@boombang
Created September 26, 2019 20:25
Show Gist options
  • Save boombang/d01ff138cd46552cc91831f73564ee22 to your computer and use it in GitHub Desktop.
Save boombang/d01ff138cd46552cc91831f73564ee22 to your computer and use it in GitHub Desktop.
type PullRequestState
= Proposed
| Rejected
| Merged
branchColor : PullRequestState -> String
branchColor state =
case state of
Proposed ->
"yellow"
Rejected ->
"red"
Merged ->
"green"
--------------------------------------------------
type Availability
= SoldOut
| InStock Int
| Reordered ( Int, Int )
| Announced String
displayStatus : Availability -> String
displayStatus availability =
case availability of
SoldOut ->
"Sold out"
InStock amount ->
"In stock: " ++ String.fromInt amount ++ " left."
Reordered days ->
let
min =
days
|> Tuple.first
|> String.fromInt
max =
days
|> Tuple.second
|> String.fromInt
in
"Available again in " ++ min ++ " to " ++ max ++ " days."
Announced date ->
"Available on " ++ date ++ "."
foo =
displayStatus (InStock 42)
-- "In stock: 42 left." : String
bar =
displayStatus (Reordered ( 3, 5 ))
-- "Available again in 3 to 5 days." : String
baz =
displayStatus (Announced "2016-12-24")
-- "Available on 2016-12-24." : String
availabilities : List Availability
availabilities =
[ SoldOut
, InStock 42
, Reordered ( 3, 5 )
]
bob =
List.map displayStatus availabilities
-- ["Sold out","In stock: 42 left.","Available again in 3 to 5 days."] : List Str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment