Last active
December 14, 2020 00:20
-
-
Save coreyhaines/ea8cf7e281f84502617b18243f991080 to your computer and use it in GitHub Desktop.
General workflow-management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Flow exposing (Flow(..), map, withDefault, mapDefault, view, update) | |
import Html | |
type Flow state | |
= NotRunning | |
| Running state | |
map : (state -> state') -> Flow state -> Flow state' | |
map f flow = | |
case flow of | |
NotRunning -> | |
NotRunning | |
Running state -> | |
Running <| f state | |
withDefault : state -> Flow state -> state | |
withDefault default flow = | |
case flow of | |
NotRunning -> | |
default | |
Running state -> | |
state | |
mapDefault : state' -> (state -> state') -> Flow state -> state' | |
mapDefault default fn flow = | |
map fn flow | |
|> withDefault default | |
view : (state -> Html.Html msg) -> Flow state -> Html.Html msg | |
view viewFn flow = | |
mapDefault (Html.text "") viewFn flow | |
update : (state -> ( Flow state, Cmd msg )) -> Flow state -> ( Flow state, Cmd msg) | |
update fn flow = | |
mapDefault ( flow, Cmd.none ) fn flow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, but what is the Irn module?