C.S.Reddy Gadipally
C.S.Reddy Gadipally

Reputation: 1758

Elm type alias with default values

I have a "Block" type alias.

type alias Block = {x:Int, y:Int, color:String}

Is it possible to have default values for x, y and color? Example, I want x and y to be 0 by default and color to be "blue".

Upvotes: 8

Views: 1080

Answers (1)

Chad Gilbert
Chad Gilbert

Reputation: 36375

You can't have default values in the way you often can in imperative languages, but this isn't a problem because you can easily define a function that sets the desired defaults:

defaultBlock : Block
defaultBlock = { x = 0, y = 0, color = "blue" }

Upvotes: 10

Related Questions