| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-10 18:08:26 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-10 18:08:26 +0200 | 
| commit | fc09d979e4c753377131684b1100c250e89765ea (patch) | |
| tree | a79689b720794b4a5503ac63ff4c84dfd04e6f41 /src/shared/elm/Shared/Update/Sequence.elm | |
| parent | d2667e46fec8f15c29ffa80925d33b6931d8aa3b (diff) | |
...
Diffstat (limited to 'src/shared/elm/Shared/Update/Sequence.elm')
| -rw-r--r-- | src/shared/elm/Shared/Update/Sequence.elm | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/src/shared/elm/Shared/Update/Sequence.elm b/src/shared/elm/Shared/Update/Sequence.elm new file mode 100644 index 0000000..ff33ae4 --- /dev/null +++ b/src/shared/elm/Shared/Update/Sequence.elm @@ -0,0 +1,37 @@ +module Shared.Update.Sequence exposing (sequence) + +-- Elm ------------------------------------------------------------------------- +import List + +-- Local Module ---------------------------------------------------------------- +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +sequence_step : ( +      (Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))) +      -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) +      -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) +   ) +sequence_step action (model, cmd_list) = +   let (next_model, new_cmd) = (action model) in +      case new_cmd of +         Cmd.none -> (next_model, cmd_list) +         _ -> (next_model, (cmd_list ++ new_cmds)) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +sequence : ( +      (List +         (Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))) +      ) +      -> (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +sequence actions model = +   let (final_model, cmds) = (List.foldr (sequence_step) (model, []) actions) in +      case cmds of +         [] -> (final_model, Cmd.none) +         [cmd] -> (final_model, cmd) +         _ -> (final_model, (Cmd.batch cmds)) | 


