Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Last active December 14, 2020 00:20
Show Gist options
  • Save coreyhaines/ea8cf7e281f84502617b18243f991080 to your computer and use it in GitHub Desktop.
Save coreyhaines/ea8cf7e281f84502617b18243f991080 to your computer and use it in GitHub Desktop.
General workflow-management
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
@MarkFarmiloe
Copy link

Nice, but what is the Irn module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment