blob: 8f5b3e901e72472bd94bbe655f617f8debd3335a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
module Shared.Update.Sequence exposing (sequence)
-- Elm -------------------------------------------------------------------------
import List
-- Local Module ----------------------------------------------------------------
import Struct.Event
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
(next_model, (new_cmd :: cmd_list))
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
sequence : (
(List
(Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)))
)
-> Struct.Model.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))
|