I am new to Elm and have been looking at the following example (note this is under the newer 0.17 architecture, where Action is now Command): http://elm-lang.org/examples/random
There is a follow up challenge to add a second die to the example, so that a single click of the button rolls a new value for each die. My idea is to change the model to hold two separate values, one for each die, ala
type alias Model =
{ dieFace1 : Int
, dieFace2 : Int
}
This works fine until I get to the update block. I am not sure how to update the Random number generator to create two values. The function is a bit confusing to me.
type Msg
= Roll
| NewFace Int Int
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Roll ->
**(model, Random.generate NewFace (Random.int 1 6))** <-- not sure what to do here
NewFace newFace1 newFace2 ->
(Model newFace1 newFace2, Cmd.none)
The documentation for the Random.generate function is a bit light -
generate : (a -> msg) -> Generator a -> Cmd msg
Create a command that will generate random values.
Is this even the correct approach to handle two dice, or is there a better way? I am an elm noob, please be nice :)