A Cmd is pretty much the same as an Effect from 0.16.

"!" is an infix operator that is pretty much just an alias for "Cmd.batch" 
(or Effects.batch from 0.16). Here's the source code for ! 
<https://github.com/elm-lang/core/blob/master/src/Platform/Cmd.elm#L64>:

{-|-}
(!) : model -> List (Cmd msg) -> (model, Cmd msg)
(!) model commands =
  (model, batch commands)


So instead of having to write something like this:

(model, Cmd.batch [ cmd1, cmd2, cmd3 ])


You can write:

model ! [ cmd1, cmd2, cmd3 ]


And instead of this:

(model, Cmd.none)


You can write:

model ! []




On Monday, May 16, 2016 at 11:33:53 AM UTC-6, Peter Bruinsma wrote:
>
> Thanks all. I'm still somewhat confused.
>
> The information architecture of the elm website is certainly not helping :)
>
> One would expect info about an operator to be somewhere under 
> elm-lang.org/docs/*
>
> However, after reading 
> http://package.elm-lang.org/packages/elm-lang/core/4.0.0/Platform-Cmd it 
> appears that (!) is not an "all-purpose" operator.
>
> Since there isn't any further explanation regarding (!) on this page 
> (apart from the type description), I decided to see if there is anything 
> else on this page that can help me understand Cmd (in general)
>
> Here we go:
> "Note: Do not worry if this seems confusing at first! As with every Elm 
> user ever, commands will make more sense as you work through the Elm 
> Architecture Tutorial 
> <http://package.elm-lang.org/packages/elm-lang/core/4.0.0/Platform-Cmd> 
> and see how they fit into a real application!"
>
> Unfortunately, that link goes nowhere. Fortunately, I know where to find 
> the Elm Architecture Tutorial (now just a chapter in the guide under 
> another subdomain because it's a gitbook...). 
>
> Nowhere in the guide is there a clear explanation of what a Cmd, a Msg or 
> a Sub is. (Oh, a Msg is not anything. It's just a user defined type. But in 
> all the examples it follows the same abbreviation pattern as Cmd and Sub, 
> so it looks like an official thing. Very confusing for a beginner!)
>
> Anyway, I typed the following in the REPL:
>
> > "" ! []
>
> ("",{ type = "node", branches = [] }) : ( String, Platform.Cmd.Cmd a )
>
> Not sure what to do with that...
>
> I guess this is not really a question anymore. I'm just venting a bit of 
> frustration :)
>
> /Peter
>
>
> On Monday, May 16, 2016 at 12:21:18 AM UTC+2, Peter Bruinsma wrote:
>>
>> For example, in TodoMVC:
>>
>> init : Maybe Model -> ( Model, Cmd Msg )
>> init savedModel =
>>   Maybe.withDefault emptyModel savedModel ! []
>>
>>
>>
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to