title: how to chain Cmd Msgs
body: <p>I have a list of <code>Cmd Msg</code>s that need to be run in order. I'm currently using <code>Cmd.batch list</code> but it seems like all of them are running simultaneously such that commands that should run later are unaware of any changes to the model the earlier commands should have introduced.</p>
  
  <p>I'm looking into <code>Task.andThen</code> but am not quite sure if that is the right direction or how to make a <code>Cmd Msg</code> out of a <code>Task</code>. Am I on the right track or is there a better way to do this, maybe that still utilizes <code>Cmd.batch</code> ?</p>
  
  <p>I currently have two functions <code>receive : String -&gt; Model -&gt; Cmd Msg</code> and <code>processMsg : String -&gt; Model -&gt; Cmd Msg</code>:</p>
  
  <pre><code>receive : String -&gt; Model -&gt; Cmd Msg
  receive msg model =
    msg |&gt; String.split "&amp;"
        |&gt; List.map String.trim
        |&gt; List.sort
        |&gt; List.map (processMsg model)
        |&gt; Cmd.batch
  
  processMsg : String -&gt; Model -&gt; Cmd Msg
  ...  (uses Cmd.Extra.message for Msg -&gt; Cmd Msg)
  </code></pre>
  
  <p><strong>edit</strong></p>
  
  <p><strong>edit2: I thought I could simplify the example by omitting that I use the model in <code>receive</code>/<code>processMsg</code> but I realized that I need the new model in order to form each subsequent message.</strong></p>
  
  <p>I'm trying to use <code>Task.sequence</code> and <code>Task.process</code> but to no success. I can get the first command to run successfully but I don't know how to expand this to get all commands to run:</p>
  
  <pre><code>receive : String -&gt; Model -&gt; Cmd Msg
  receive msg model =
      let 
          msgs = 
              msg |&gt; String.split "&amp;" 
                  |&gt; List.map String.trim
                  |&gt; List.sort
                  |&gt; List.head
                  |&gt; Maybe.withDefault "none"
                  |&gt; Task.succeed
      in
          Task.perform Oops (processMsg model) msgs
  
  processMsg : String -&gt; Model -&gt; Msg
  ...
  </code></pre>
  
  <p>I thought about changing <code>processMsg</code> to <code>processMsg : String -&gt; Task String Msg</code> but then I have no idea what to supply for the second argument of <code>Task.perform</code>. I'm not sure how <code>Task.sequence</code> figures into this because when I try to insert it into the pipe I just end up with</p>
  
  <p><code>List (Task x String) -&gt; Task x (List String) -&gt; Task x (List Msg) -&gt; Cmd (List Msg)</code></p>
  
  <p>which I don't know what to do with.</p>