Hi Matt,
Thanks for your nice answer!
> As for Dicts, I would say double check to make sure you don't
> actually want a record. Basically if you know all the fields at
> compile time...you probably want a record, not a dict.
I may have an habit of using dicts too often... (in python, almost everything is a dict anyway ;-) )
What do you think? in my code I have
type alias Model =
{ lines : Dict String Line
, from : String
, to : String
[...]
}
type alias Line =
{ name : String
, from : String
, to : String
[...]
}
The Dict content is static, but I chose a Dict in order to be able to iterate over it, as in
getTimes : Model -> Cmd Msg
getTimes model =
Cmd.batch <| List.map getLineTimes (Dict.values model.lines)
I also need to find a line from its name because each line has its own Http.get and needs to get the value back
type Msg
= FetchSucceed String (List String)
| ...
update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
case action of
FetchSucceed name times ->
{ model
| lines =
let
line =
case Dict.get name model.lines of
Just l ->
l
Nothing -> -- should never occur!
Line name "" "" [] [] Nothing
[...]
in
Dict.insert name newLine model.lines
It seems to me that if I replace my Dict by a record I'll have to deal with each line separately. But maybe I'm missing something?
One thing that bothers me is that I must provide some code for the case when the key is not in the dict, although I know by design that it will not happen. This could be avoided by using records, of course.
> So for something like `[i +5 for i in range(20)]` in python, you could do something like `List.map ((+) 5) [0..20]`
Right, but I still like how python comprehensions allow to combine map, filter and cartesian product in a simple, short syntax!
> Cheers and again, welcome to elm.
Thanks :-)
Matthieu